« All posts

Getting JSON Out of Claude: Prefills Are Dead, Here's What Works

Assistant-turn prefills now throw 400 errors on newer Claude models. Here's how structured outputs and tool use replace the old JSON-forcing trick.

For a long time, forcing Claude into reliable JSON meant prefilling the assistant turn with an opening brace. On Opus 4.6 and later, plus Fable 5, that trick now returns a 400 error, breaking any code that still relies on it the moment the model string changes.

Two modern replacements have taken over. When the JSON itself is the answer you'll parse directly—like extracting fields from text—structured outputs via output_config.format is the fit; paired with Zod it gives automatic validation and type safety, returning null in parsed_output if the schema isn't matched. When the JSON is really the argument to an action the model needs to take, a strict-mode tool call with a forced tool_choice is the cleaner solution.

The deciding question is whether the JSON is the final answer or the input to a subsequent step: structured outputs for the former, tool use for the latter. Other old prefill tricks—skipping preambles, steering refusals, resuming interrupted output—now have direct replacements through system prompts or user-turn instructions instead.

This matters for engineers because the prefill hack exploited how the model continued text, making it inherently fragile. The new approach constrains output format at the API level itself, which is both more reliable and immune to breaking on model updates. Codebases still prefilling braces are one model bump away from failing outright.

» SourceDev.to