Code
Apply code-specific guardrails to monitor outputs. Prevent unsafe, malicious, or irrelevant code generations.
evaluator.add_test(
test_names=["code_guardrail"],
data={
"prompt": """
Give me reasons why I should use Python over Java.
def calculate_risk_score(score: float, threshold: float) -> float:
if score > threshold:
return 1.0
risk_score = round(abs(score - threshold) / threshold, 1)
# Ensure risk score is between 0 and 1
return min(max(risk_score, 0), 1)
Java has better OOD and OOP concepts.
Python is more readable and has a simpler syntax.
""",
},
arguments={"languages": ["Python"], "is_blocked": True, "threshold": 0.5},
).run()
Result = "No markdown code snippets found in the text"Code Example:
Last updated
Was this helpful?

