◉ANTIGRAVITY LABJP
Articles/Integrations
⬡ Integrations/2026-06-27Intermediate

Pass Your Agent's Structured Output Downstream With Schema Validation and Bounded Repair

Before the JSON an Antigravity agent returns flows straight into downstream automation and causes an incident, build a safe boundary with JSON Schema validation and a turn-limited repair loop. Includes the implementation.

Antigravity377integrations21JSON-Schemavalidation5agent-design10

✦ Premium Article

Ask an agent to "return the next article candidates as JSON" and most of the time you get clean JSON. Most of the time. About once a week, a preamble sneaks in, a trailing comma appears, or level comes back as "beginner-intermediate", a value that does not exist.

The problem is that the one broken case flows into downstream automation. I run several sites on my own, with a process that takes the agent's output and assembles MDX. If the JSON parse fails, that whole generation is wasted. Even with a smart model, this incident never reaches zero unless you place validation at the boundary of the output.

Agent output is "untrusted input"

The first mindset to hold is to treat agent output the same as input from outside.

Nobody puts a value from a web form into the database without validating it. Yet generative output somehow tends to get passed downstream unvalidated. Because the output is linguistically fluent, you mistake the structure for correct too. Fluency and correctness are different things. Place a single validation layer at the boundary and the downstream code can be written on the assumption that "only the correct shape arrives."

Make the "shape" a contract with JSON Schema

First, write the shape the downstream expects as a schema. Not vague prose inside the prompt, but a contract a machine can judge.

ARTICLE_PLAN_SCHEMA = {
    "type": "object",
    "required": ["title", "slug", "category", "level", "tags"],
    "additionalProperties": False,
    "properties": {
        "title": {"type": "string", "minLength": 8, "maxLength": 60},
        "slug": {"type": "string", "pattern": "^[a-z0-9-]+$"},
        "category": {"enum": ["agents", "integrations", "tips", "editor"]},
        "level": {"enum": ["beginner", "intermediate", "advanced"]},
        "tags": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 2,
            "maxItems": 6,
        },
    },
}

enum pins level to three values, and pattern keeps periods and uppercase out of the slug. additionalProperties: False matters too: if the model helpfully adds an extra key, it gets rejected. A schema is the tool that promotes the "request" in your prompt into an unbreakable "promise."

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦A concrete layer design that treats agent output as a trust boundary and never passes it downstream unvalidated
✦Locking type and required fields with JSON Schema, plus a turn-limited repair loop that self-heals broken output
✦Fallback and logging design that prevents infinite repair and runaway cost on failure
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $15 for lifetime access
View Membership →

Related Articles

⬡ Integrations2026-09-20
antigravity-preview-05-2026 shuts down October 5: which setups need more than a string swap
The shutdown date for antigravity-preview-05-2026 is set for October 5, and the official page gives you the date and the successor name, nothing more. If you only read output_text, swapping the string is the whole migration. If you read steps, it is not.
⬡ Integrations2026-09-18
When a session starts with MCP tools missing, where do you stop?
When MCP initialization fails at startup, the agent quietly falls back to other means and keeps going. Here is a small script that asks your servers directly which tools they expose, plus the three branches I decided on in advance for when something is missing.
⬡ Integrations2026-09-05
Pointing GOOGLE_GEMINI_BASE_URL at Your Own Gateway Does Not Change Who Holds the Key
I pointed the Antigravity CLI at a gateway of my own and recorded exactly which credentials travelled with it. Authorization is dropped across a cross-origin redirect, but the API key header survives every hop. Here is the measurement, and how I moved the key off my laptop.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links