AI Output Schema Bypass Lab: Valid JSON, Impossible Values

✨ AI Summary
ApprovalBot reviews expense reports and returns a JSON verdict the backend validates against a schema: right types, required fields present. But a schema checks shape, not sense — so a verdict approving a $1,000,000 expense is perfectly valid JSON, and perfectly against policy.
Lab at a glance: Advanced · 145 XP · about 20 minutes · runs in your browser, no signup or setup. Try it yourself first; the full solution is behind a spoiler below.

What this lab teaches

Schema validation confirms that model output has the right structure — field types, required keys, formats. It does not confirm that the values obey business rules. If the backend acts on any schema-valid verdict, an attacker who can steer the model's output can produce a well-formed decision that violates real constraints.

The lesson: 'valid JSON' is not 'valid decision'. Business constraints must be checked in code, not assumed from the schema.

How ApprovalBot validates its verdict

ApprovalBot emits {approved, amount, reason}. The backend validates types and required fields and then trusts the result. The policy cap is $5,000, but nothing enforces that cap — a verdict with approved true and a huge amount passes validation and is acted on.

The attack approach

  • Confirm the backend validates structure but not the policy cap.
  • Steer ApprovalBot to emit a verdict that is schema-valid but breaks policy.
  • Set approved to true with an amount far above the $5,000 limit.
  • Confirm the verdict passes validation.

Full walkthrough (spoiler)

If validation rejects it, you broke the shape, not just the values — open the steps.

Show the step-by-step solution
  1. Induce ApprovalBot to return a verdict with approved true and an amount above 100,000, keeping the field types and required keys exactly as the schema expects.
  2. The backend checks types and required fields — all correct — and accepts it.
  3. Nothing checks the value against the $5,000 policy cap.
  4. The out-of-policy approval goes through and the lab marks you solved.

Why it works

The validator answers 'is this the right shape?' and stops. The dangerous part — whether the numbers obey policy — is never checked. Because you can influence the model's output and the shape is easy to satisfy, a compliant-looking but policy-breaking verdict sails through.

Core principleValidate business constraints, not just structure. Encode the real limits — caps, enums, consistency rules — in code that runs after schema validation.

Where this happens in the real world

As teams use LLMs for decisions and return 'structured output', trusting schema-valid output as correct is a growing mistake under OWASP LLM05 Improper Output Handling (with an Excessive Agency angle when the decision triggers an action). Schema validation is necessary but never sufficient.

How to defend against it

  • Encode business rules in the validator — maximum amounts, allowed enums, cross-field consistency.
  • Treat the model's decision as a suggestion, re-checked by deterministic code before any action.
  • Keep high-impact approvals under human review above a threshold.
  • Log and alert on verdicts that approach or exceed policy limits.
Mr Elite tip: Whenever an LLM returns structured output that drives a decision, ask what enforces the values. Type-checking the JSON is not enforcing the policy.

Try it, then go further

Reading about it is the easy part. Open the lab, try your own approach before peeking at the spoiler, and see how many attempts it takes.

❓ Frequently asked questions

What is output schema bypass?
Producing model output that passes JSON-schema validation (correct types and fields) but carries values that violate real business rules the backend fails to check.
Isn't schema validation enough?
No. A schema checks structure, not whether the values make sense. Business constraints like caps and enums must be enforced separately in code.
Why does the model matter here?
Because an attacker can steer the model's output; if the backend trusts any schema-valid verdict, a well-formed but out-of-policy decision gets acted on.
How do I prevent it?
Add value-level validation after schema checks, treat the model's decision as a suggestion re-verified by code, and keep high-impact actions under human review.
⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *