Result
Status: Beta Companion docs: Verdicts and modes · Public verification API · Masking API
Turn any governed response into one GovernanceResult. You can branch on a clear verdict, show a corrected answer, protect masked data, or send a risky action to review.
response = tr.client(
"openai",
credential="cred_openai_prod",
).chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Summarize ticket 4821."}],
)
result = tr.result(response)
print(result.verdict)
One result, six outcomes
result.verdict is one of:
| Verdict | What your app should do |
|---|---|
passed | Use the response |
corrected | Use the corrected response and inspect result.diff |
blocked | Stop the action or show a safe fallback |
masked | Keep tokens outside the trust boundary, then unmask in an approved path |
HiTL | Pause and use result.review for a human decision |
failed | Follow your service's error policy |
The SDK can read the verdict from the response body or from the governance response header. Wire values such as governance_blocked are normalized to blocked.
Read the common fields
result = tr.result(response)
print(result.id)
print(result.verdict)
print(result.diff)
print(result.violations)
print(result.compliance)
print(result.risk)
print(result.scope_id)
| Field | Return value |
|---|---|
id | Decision or result ID, when present |
verdict | Normalized six-value verdict |
diff | RFC 6902 patch operations, or [] |
violations | Found violations, or [] |
compliance | Framework rows, or [] |
risk | Risk data, or None |
scope_id | Scope ID, or None |
flow_id | Masking flow ID, or None |
mask_manifest_hash | Mask manifest hash, or None |
retrieval | Retrieval data, or None |
provenance | Output provenance data, or None |
cost_center | Cost label, or None |
cost_usd | Captured provider cost, or None |
routed_model | Model selected by routing, or None |
failover_triggered | Whether model failover ran |
Optional fields stay optional. Check for None before using them.
Handle a corrected result
diff is an array of RFC 6902 patch operations. It is empty for other verdicts.
result = tr.result(response)
if result.verdict == "corrected":
for operation in result.diff:
print(
operation["op"],
operation["path"],
operation.get("value"),
)
The Guardian can fix a response instead of forcing your app to drop useful work. Your app can keep moving while still recording exactly what changed.
Inspect violations and controls
result = tr.result(response)
for violation in result.violations:
print(violation.get("code"))
for control in violation.get("controls", []):
print(control)
This gives the application a simple security decision and gives review tools structured details. The rationale summary is available as result.rationale. When the result has an ID, fetch the full structured trace with:
trace_response = result.explain()
if trace_response.ok:
for step in trace_response.body.get("steps", []):
print(step)
result.explain() needs both a result ID and the client attached by tr.result(...).
Rehydrate a masked reply
When masking ran, the result carries a flow ID. Pass the model text to result.unmask(...) inside your approved trust boundary.
result = tr.result(response)
if result.verdict == "masked":
masked_text = result.body["choices"][0]["message"]["content"]
unmask_response = result.unmask(masked_text)
if not unmask_response.ok:
raise RuntimeError(unmask_response.body)
safe_for_internal_use = unmask_response.body["text"]
result.unmask(...) raises ValueError when the result has no flow_id. The SDK sends the result's manifest hash with the unmask request when it is available.
Continue a human review
result.review is available only for HiTL results that include a review request ID.
result = tr.result(response)
if result.verdict == "HiTL" and result.review is not None:
decision = result.review.approve(
reason="Order and refund limit were verified.",
)
For every other verdict, result.review is None. This keeps high-impact AI actions paused until a person makes the needed decision.
Verify a receipt
The receipt block has id and verify_url. It may be absent.
result = tr.result(response)
if result.receipt and result.receipt.get("id"):
verification = result.receipt.verify()
if not verification.ok:
raise RuntimeError(verification.body)
print(verification.body.get("verified"))
Receipt verification uses the public verification endpoint and does not send bearer authentication. This lets another system check the receipt without receiving your API key.
Keep the raw response when needed
GovernanceResult keeps access to the normalized wire data:
result = tr.result(response)
print(result.status)
print(result.ok)
print(result.headers)
print(result.body)
print(result.response)
This is useful for debugging, while the named result fields keep normal app code short.
Where to go next
- Verdicts and modes: design each outcome path.
- Scopes and assets: add the goal and asset context behind a result.
- Identity: give autonomous AI a limited, traceable identity.