Search⌘ K
AI Features

Add a Self-Check That Fails Safe

Explore how to design and implement self-checking prompts that audit AI-generated JSON outputs for schema compliance. Understand the importance of fail-safe flags to handle uncertain or incorrect values, ensuring workflows safely escalate when outputs are unrouteable. This lesson guides you through crafting prompt layouts that maximize reliability and reduce silent failures in automated triage systems.

Syntactically valid JSON can still paralyze an automated workflow if a single value drifts outside your allowed enums. For instance, if an AI returns category: "payments_issue" instead of the required "billing", your router rules will fail to match any branch, dumping the ticket into a default queue without throwing an explicit error. To prevent these silent failures, your prompt needs an inline self-check that audits draft decisions before finalizing output. In this lesson, we will explore how to write self-checking prompts that flip explicit fail-safe flags whenever uncertainty or schema violations occur.

To see how this failure surfaces, inspect a few triage outputs and note which fields violate the schema and which routing rule would fail to match:

Triage JSON fails schema checks and falls to default routing, until a self-check catches it and forces a safe escalation
Triage JSON fails schema checks and falls to default routing, until a self-check catches it and forces a safe escalation

Start with the raw output a model produced for one ticket:

{
"category": "payments_issue",
"priority": 5,
"next_action": "reply"
}

Note: needs_human is missing entirely.

Running that JSON through the schema catches three separate problems at once:

Schema Check Failures
ViolationFieldDetail

Enum mismatch

category

must be one of: billing, bug, account, how_to, other

Wrong type

priority

must be a string (low, normal, high), not a number

Missing key

needs_human

required (boolean)

Do you find this helpful?

None of those problems throw an error on their own, so the next question is what happens when the router actually tries to act on this JSON.

Router Rules Against the Bad JSON
RuleMatch conditionResult

Rule 1: Auto-reply

category in allowed set and needs_human == false

No match

Rule 2: Known priority

priority == "high"

No match

Rule 3: Known category

category in {billing, bug, account, how_to, other}

No match

Do you find this helpful?

Result: No rules matched. Falling back to default bucket, UNREVIEWED_QUEUE.

A self-check applied before that point would have rewritten the JSON into something the router can act on safely. ...