Syntax Guard
The Syntax Guard is an output guard that analyzes the responses generated by your language model to ensure they adhere to proper syntax, formatting, and escaping rules. It helps in identifying issues such as unconverted placeholders, incorrect escaping, punctuation errors, and inconsistent formatting, ensuring the outputs are syntactically correct and well-structured.
SyntaxGuard
is only available as an output guard.
Here's what an unsafe output would look like in the context of incorrect syntax:
"Welcome {{user_name}}! Your order has been placed."
— probably your LLM
Example
Since SyntaxGuard
is an output guard, simply provide it as a guard in the list of guards
when initializing a Guardrails
object:
from deepeval.guardrails import Guardrails, SyntaxGuard
guardrails = Guardrails(guards=[SyntaxGuard()])
Then, call the guard_output
method to make use of the SyntaxGuard
:
...
output = generate_output(input)
guard_result = guardrails.guard_output(input=input, output=output)
print(guard_result)
There are no required arguments when initializing a SyntaxGuard
.
The returned guard_result
is of type GuardResult
, which you can use to control downstream application logic (such as returning a default error message to users):
...
print(guard_result.breached, guard_result.guard_data)