from murnitur import Guard
from murnitur.guard import Payload, RuleSet
# Define the contexts and actual output
contexts = [
"Einstein won the Nobel Prize for his discovery of the photoelectric effect.",
"Einstein won the Nobel Prize in 1921.",
]
output = "Einstein won the Nobel Prize in 1969 for his discovery of the photoelectric effect."
# Create a payload
payload: Payload = {"output": output, "contexts": contexts}
# Create rulesets
rulesets: list[RuleSet] = [
{
"rules": [
{
"metric": "ctx_adherence",
"operator": "greater_than_equal",
"value": 0.25,
}
],
"action": {
"type": "OVERRIDE",
"fallback": "I don't have enough information to answer your question.",
},
}
]
# Use the shield to check for hallucination
result = Guard.shield(payload, rulesets)
print(result.triggered)