Valid JSON, Wrong Shape: Structured Output Across Three AI Backends
On March 3rd, 2026, a planning step in our content pipeline asked the model for a list of entities and got back exactly what it asked for. That was the problem. The prompt said: return the entities as JSON. The model returned JSON. Perfectly valid JSON. Any parser on earth would have accepted it. What it returned was this: [ "prompt-caching" , "context-windows" , ... ] What the code expected was…
On March 3rd, 2026, a planning step in the content pipeline requested the model to return entities as JSON. The model complied, returning valid JSON. However, the code expected a specific structure, a JSON object with an "entities" field. The bare top-level array instead of an envelope object led to a schema failure, a layer that the parse failure alone could not catch.
The two-layer fix involved including the exact JSON schema in the prompt and adding a fallback to automatically wrap the bare array if needed. This approach, known as schema-in-prompt, is a portable layer of defense against structured JSON output issues, especially when native enforcement is not available or identical across all AI backends.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.