Skip to main content

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:

VerdictWhat your app should do
passedUse the response
correctedUse the corrected response and inspect result.diff
blockedStop the action or show a safe fallback
maskedKeep tokens outside the trust boundary, then unmask in an approved path
HiTLPause and use result.review for a human decision
failedFollow 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)
FieldReturn value
idDecision or result ID, when present
verdictNormalized six-value verdict
diffRFC 6902 patch operations, or []
violationsFound violations, or []
complianceFramework rows, or []
riskRisk data, or None
scope_idScope ID, or None
flow_idMasking flow ID, or None
mask_manifest_hashMask manifest hash, or None
retrievalRetrieval data, or None
provenanceOutput provenance data, or None
cost_centerCost label, or None
cost_usdCaptured provider cost, or None
routed_modelModel selected by routing, or None
failover_triggeredWhether 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