◉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.

Antigravity419integrations21JSON-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 $10 for lifetime access
View Membership →

Related Articles

⬡ Integrations2026-11-19
When an Agent Says the Integration Is Done: Checking a Claims List With a Small Verifier
An agent can report that an integration task is finished while the real files, commits, and served responses lag behind. Here is how I have the agent write its report as a claims.json, then check each claim with a separate script: files, commits, commands, and live endpoints, with working code.
⬡ Integrations2026-11-02
Three things to check on a Marketplace partner plugin's page before you install it
Antigravity 2.28.2 put partner plugins into the Marketplace. Here is how I split the decision: check the developer and repository before installing, then manage the connection from the Accounts tab afterward, plus a short command to see whether a repository is still maintained.
⬡ Integrations2026-10-26
I Stopped Embedding the Token in the Remote URL. An Old Clone's .git/config Had It Sitting There, Readable by Anyone
How to audit unattended git jobs for tokens embedded in the remote URL and move them to http.extraheader. Full text of three scripts plus the real output from before and after the migration.