Signal
One schema, three LLM providers: checking structured output after the model says yes
Signal sends one plan schema to OpenAI, Claude and Gemini, then re-checks every response locally: bounds, finish signals and real evidence ids.
In short
Claude's structured outputs don't accept some JSON Schema keywords, so Signal moves bounds such as 0 to 5 scores into field descriptions, which means a 6 can come back looking valid. Every provider's response gets its own completion check, then the same Zod plan schema and an evidence-grounding check. Failures return an actionable error, with no repair, no automatic retry and no fallback to another provider.
Signal is a small content-planning app I built for my own job search. It reads my résumé, project notes and saved job descriptions, then asks a large language model for topics I can credibly write about, each scored for fit, demand and proof and citing its evidence. The model can be OpenAI, Claude or Gemini, picked with one environment variable.
Here's the detail that shaped the code: the schema Signal sends to Claude doesn't say a score must be between 0 and 5. Claude's structured outputs don't accept some JSON Schema keywords, so those limits are taken off the schema and written into the field's description as plain text. A topic scored 6 can come back looking perfectly valid. For someone using Signal, that would mean a plan that looks finished but ranks topics on numbers the app never allowed.
Think of sending the same technical drawing to three workshops. One of them can't read tolerances off a drawing, so you write them in the margin and hope they're followed. Whatever the workshop says when it ships, you still measure every part when it arrives.
What happens on one planning request
The planner builds one JSON Schema for the plan: a summary and 1 to 8 topics, each with required fields, additionalProperties: false, an outline of 3 to 5 strings, and fit, demand and proof as integers from 0 to 5. Then it branches by provider.
OpenAI gets the schema unchanged through the Responses API, with strict: true and store: false. Gemini gets it as a responseFormat with mimeType: "application/json". Claude gets a rewritten copy from anthropicSchema, which walks the schema and pulls out minimum, maximum, minLength, maxLength, maxItems and any minItems above 1:
if (Object.keys(constraints).length)
result.description =
`${result.description || ""} Required constraints: ${JSON.stringify(constraints)}.`.trim();
So fit arrives at Claude as an integer with a description that says Required constraints: {"minimum":0,"maximum":5}. The model is told the rule, but the decoder no longer enforces it. That's the margin note on the drawing.
Three responses, one shape
Each provider says "I finished" differently, so each gets its own check before any JSON is parsed. OpenAI needs status: "completed" and no refusal block. Claude needs stop_reason: "end_turn". Gemini needs finishReason: "STOP", and parts marked thought are dropped so reasoning text never gets glued into the JSON. Anything else ends in one error: the model returned an incomplete or refused plan.
Then the object goes through the same checks whichever provider produced it. A Zod planSchema enforces the bounds Claude only read as prose: integer scores from 0 to 5, an outline of 3 to 5 items, a title of at most 180 characters. After that, validateGrounding checks what no schema can express. Topic ids must be unique. Every cited sourceId has to exist in the user's library, and at least one must be a project or experience source. A topic that cites no job description or market research gets demand set to 0, whatever the model said.
Strict where it matters, no quiet fallback
The obvious alternative was to trust provider validation. For Claude that can't work, because the bounds were removed on purpose, and I didn't want correctness to depend on which provider happened to be selected. One local schema for all three costs a little duplication and buys one definition of a valid plan.
The other decision was what failure looks like. A malformed plan isn't repaired, and there's no fallback to another provider, even when its key is configured. A silent switch would change the model, the price and the output style without the user knowing. Signal shows an actionable error, and paid requests aren't retried automatically. A 429 becomes "The provider returned 429" plus advice, never the upstream body. Requests time out after 45 seconds.
One side effect needs saying plainly. On the Claude path, a usage-ledger row is written to SQLite before the paid request and updated with the reported tokens afterwards, refusals included. A plan rejected locally has still been paid for, and the ledger shows it. Each retry gets its own entry.
How it's tested
tests/llm.test.ts runs the same cases against all three providers with fetch mocked. "uses the native endpoint, authenticates in headers, and validates its output" also checks that Claude's schema lost maxItems on topics, gained it in the description, and has no minimum on fit. "rejects incomplete and refused output without switching providers" asserts exactly one fetch call. "rejects out-of-range scores even if the provider accepts them" returns fit: 6 from each provider and expects rejection. "requires the selected provider configuration without falling back" selects Claude with only OpenAI configured and checks that nothing is sent. In tests/planner.test.ts, "rejects fabricated citations and duplicate identities" and "removes unsupported demand scores from model output" cover grounding.
These prove how my code handles each response shape, not how the live APIs behave today. If a provider changes its response format, the mocks won't notice.
What carries over
- Keep one local definition of valid output and run it after every provider, even ones with strict decoding.
- When you loosen a schema for one provider, write down what you dropped and enforce it yourself.
- Check each provider's finish signal before parsing. A truncated JSON object is still truncated.
- Validate references against your own data. A schema can say "string"; only your database knows whether that id exists.
- Don't fall back to another model without telling anyone. Fail, explain, and let the person retry.
For the person planning their writing, a plan arrives with scores in range and citations that point at their own evidence, or it doesn't arrive and they see why. The design behind that is small, one schema, three thin adapters and a shared validator, and it's why switching from Gemini to Claude changes the model but not the rules. A workshop that ignores the margin note still gets measured at the door.
Further reading
- OpenAI structured outputsdevelopers.openai.com
- Claude structured outputsplatform.claude.com
- Gemini structured outputai.google.dev
- JSON Schema validation keywordsjson-schema.org
More writing
-
Don't let the model convert the calendar: Jalali dates in an MCP server for a gold inventory
Why a gold inventory's MCP server converts Jalali dates itself, rejects days that don't exist, and returns every date in both calendars to AI agents.

-
A cold start that draws last launch: persisting the TanStack Query cache in a mobile word game
How ClueShot restores last launch's TanStack Query cache as stale, checks whose it is, and revalidates with ETags so a cold start never opens empty.

-
Two failure handlers, one refund: idempotent cleanup in an async AI image pipeline
How a BullMQ image worker, its failed event and a Telegram bot all reach one refund in MrPicasso, and how two Redis claims keep it to one credit.
