All posts

AI Engineering

Valid JSON, Wrong AI Classification: Catch Prompt and Schema Description Drift

Separate output shape from meaning. Compare official schema documentation with research, then reproduce a small Node.js contract-drift check without calling a model.

Published and maintained by Sambro · Report a correction

6 min read Structured outputJSON SchemaAI evaluationAPI integration

Valid JSON can still route a request to the wrong team

Imagine a classification API returning {"label":"Z2"}. The JSON parses and the label is allowed. But Z2 means technical support, while the request concerns a duplicate charge. Passing a format check is not the same as answering the business question correctly.

Keep structured output. Generate the prompt and schema descriptions from one label registry, then test meaning separately. The downloadable example below is a deterministic test, not a model call.

A description is not a validation constraint

The official JSON Schema documentation describes title and description as annotations, not validation rules. If enum allows Z1 and Z2, swapping their meanings in a description does not make the string Z2 invalid. JSON Schema: annotations

Google’s Gemini structured-output documentation, meanwhile, says title and description guide the model. Text ignored by validation can still influence generation. Both are living official documents checked on October 26, 2026; we did not establish fixed publication dates. Gemini: structured output

Read the research within its tested scope

Sin-Ying Lin submitted the arXiv preprint Your Prompt Is Not the Only Prompt: How Much Do LLMs Weight Structured-Output Schema Descriptions? on August 8, 2026. It studies instruction placement and conflict, including strongly permuted label definitions in single-field classification. Additional multi-field experiments did not establish reliable placement effects. It is not proof of a universal instruction hierarchy. Your Prompt Is Not the Only Prompt — arXiv

We do not reproduce its performance figures or evaluate a model here. The engineering question is narrower: do the prompt and schema descriptions maintained by our application describe different policies?

The contract check we actually ran

We ran the example on October 26, 2026 with Node.js 24.22.1. One registry defines Z1 = billing and Z2 = technical, generating both prompt and schema. A separately constructed stale schema reverses only the description.

For an invented duplicate-charge request with a manually assigned reference label Z1, a hand-written Z2 response passes the shape check but fails reference comparison. Contract comparison reports schema drift. This demonstrates separate checks; it does not show that an AI produced this response.

Check one response against two different requirements
Input: Please explain the duplicate charge on my invoice.
Reference label: Z1 (billing)
Response: {"label":"Z2"}
shape_valid: true
meaning_matches_fixture: false
stale_contract_errors: ["schema"]

What this code does and does not catch

shapeValid implements only this example’s object, required label, string, allowed-label and no-extra-field checks. It is not a general JSON Schema validator. In production, use a validation library and verify the schema dialect and subset supported by your API.

driftErrors compares against the generated canonical contract exactly. Equivalent wording also counts as a change. It does not understand arbitrary prose, detect prompt injection, or repair an incorrect policy in the source registry. Policy review and independent reference labels remain necessary.

Keep three checks separate in production

First, generate the contract. Maintain label and field definitions centrally and generate prompt and schema together. Do not add unsupported schema keywords. Recording model, prompt and schema versions together helps locate regressions.

Second, validate shape after parsing: fields, types, enums and required values. Handle refusals and interrupted responses as separate states instead of coercing them into normal classifications.

Third, evaluate meaning using separate billing, technical and ambiguous examples with human-checked references. Re-run these regressions after policy or model changes. Passing semantic evaluation is still not authorization to send external messages or make payments.

Download and reproduce

Code: schema contract — demo.mjs · Tests: schema contract — demo.test.mjs · Saved result: schema contract — results.json

Save the three files in one folder. No package installation, API key or network access is needed. Eight tests passed, covering swapped descriptions, stale prompts, wrong labels, missing and extra fields, and other cases.

Run with Node.js 22 or newer
node --test demo.test.mjs
node demo.mjs

One useful change to your next review

When a pull request changes label policy, review the generated prompt and schema descriptions together, not just a sample output. This catches a simple mismatch before release without abandoning structured output. It is an engineering recommendation, not a promise of better model accuracy or complete security.

Inspect result JSON with the free formatter: JSON formatter . Continue with confidence versus correctness: Can a 90% LLM Confidence Score Justify Automatic Processing? . For workflow API integration and review interfaces, see Sambro — company and services

Back to Sambro Blog