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.
info
SyntaxGuard
is only available as an output guard.
Example
from deepeval.guardrails import SyntaxGuard
model_output = "Welcome {{user_name}}! Your order has been placed."
syntax_guard = SyntaxGuard()
guard_result = syntax_guard.guard(response=model_output)
There are no required arguments when initializing the SyntaxGuard
object. The guard
function accepts a single parameter response
, which is the output of your LLM application.
Interpreting Guard Result
print(guard_result.score)
print(guard_result.score_breakdown)
guard_result.score
is an integer that is 1
if the guard has been breached. The score_breakdown
for SyntaxGuard
is a dictionary containing:
score
: A binary value (1 or 0), where 1 indicates that outdated content was detected.reason
: A brief explanation of why the score was assigned.
{
"score": 1,
"reason": "The output contains an unconverted placeholder '{{user_name}}'."
}