---
title: "Structured Output & Function Calling Under Stress: 5 Production Failure Modes Across 201 Calls"
published: true
description: "100% valid JSON doesn't mean 100% accurate arithmetic, and tool_choice isn't a 100% guarantee. Here are 5 real failure modes observed across 201 live API calls."
tags: llm, agents, json, benchmark
series: Production AI Benchmarks
In a demo, getting valid JSON once feels like a solved problem. In production—at tens of thousands of Agent calls per day—a 1% drift rate (one extra line of prose, a miscalculated total, or a model asking the user a question instead of calling a tool) will stall your state machine at 3 AM.
We ran 201 live requests (2026-11-17, via DashScope, total cost ¥2.6166) across four models to test repeated consistency on two tasks:
-
S1 / S1R: Nested customer-support JSON extraction (
89900 + 3×3900 − 6000 = 95600integer cents), tested prompt-only (S1,n=10) and withresponse_format: {"type": "json_object"}(S1R,n=10). -
S2 / S2T: 6-tool routing where the prompt mandates
query_inventoryas step 1, tested prompt-only (S2,n=20) and with explicittool_choice=query_inventory(S2T,n=10).
(Note: glm-5.3-prime rejected enable_thinking=false on DashScope with The value of the enable_thinking parameter is restricted to True, so it ran with thinking enabled while the other three ran with thinking disabled.)
Results Matrix (201 Live Calls)
| Model |
S1 (Prompt JSON) |
S1R (json_object) |
S2 (Prompt Tool) |
S2T (tool_choice) |
Avg Cost / Call |
|---|---|---|---|---|---|
qwen3.8-max (no-think) |
10/10 |
10/10 |
20/20 |
10/10 |
¥0.0079 |
deepseek-v4-pro (no-think) |
2/10 |
5/10 |
7/20 |
9/9 (+1 HTTP 400) |
¥0.0081 |
glm-5.3-prime (thinking on*) |
10/10 |
10/10 |
19/20 |
7/10 |
¥0.0268 |
kimi-k3.1-pro (no-think) |
10/10 |
10/10 |
0/20 |
10/10 |
¥0.0098 |
The 5 Production Failure Modes We Actually Observed
-
Perfect JSON, Wrong Arithmetic (
deepseek-v4-proonS1/S1R): 7 of 8S1failures returned valid JSON with"payable_cents": 95000instead of95600. Addingjson_objecteliminated Markdown fences (S1R), but5/10still failed arithmetic (95000,104600,95700,93000). Schema validation cannot catch business-logic math errors—always recompute totals in code. -
"Reasonable Detours" (
kimi-k3.1-pro20/20,deepseek-v4-pro9/20onS2): Instead of callingquery_inventoryfirst as instructed,kimi-k3.1-procalledquery_orderevery single time ("to verify the SKU first"). Reasonable logic, 100% workflow violation. Enforcingtool_choicefixedkimi-k3.1-proto10/10. -
Replying to the User Instead of Calling a Tool (
deepseek-v4-pro4/20,glm-5.3-prime1/20): When uncertain, models fall back to conversational clarification. Your Agent state machine must explicitly handle ano tool_callsbranch. -
tool_choiceIs Not Always Hard-Enforced (glm-5.3-prime3/10onS2T): Even withtool_choice=query_inventoryexplicitly set,glm-5.3-primecalledquery_ordertwice and replied"好的"(no tool call) once. Never treattool_choiceas a 100% guarantee without code-level assertion. -
Transient Server-Side Grammar Timeout (
deepseek-v4-pro1/10onS2T): Onetool_choicerequest returned HTTP 400:grammar validation or compilation failed: sandbox grammar compile timed out. Clients must catch 4xx/5xx grammar errors and apply idempotent retry/fallback.
Bonus safety check: Across all 199 successful responses, zero models erroneously triggered destructive write tools (refund, create exchange order, send SMS).
Engineering Guardrails Checklist
- ☐ Treat
tool_choiceas a hint and asserttool_calls[0].function.namein code. - ☐ Handle
no tool_callsexplicitly in your state machine. - ☐ Extract raw quantities/prices with the LLM, but compute financial totals in deterministic code.
- ☐ Align
enable_thinkingflags between staging evals and production—toggling it changes both latency and accuracy.
Next in **Production AI Benchmarks: Multimodal Vision Models on Dirty Invoices, UI Restoration, and Architecture Diagrams.
Reproducible Scripts & Sponsorship
- GitHub Benchmark Suite: https://github.com/wangguode/llm-prod-bench
- Chinese Full Report (Zhihu): https://zhuanlan.zhihu.com/p/2106135589607170990
- Building an LLM gateway, inference platform, or Agent DevTool and want an independent production stress-test? Open a
[Benchmark Request]issue on GitHub or DM @sansaxypy.
Top comments (1)
The S1 numbers are the interesting part, but they only mean what you want them to mean if temperature and seed were pinned. If those runs used the default sampling, "repeated consistency" is really measuring sampling variance - deepseek's 2/10 is one draw of ten, and with n=10 the CI on that is wide enough that 2/10 and 5/10 are not clearly different models of behaviour, just different luck on the arithmetic. Same for glm-5.3-prime: it is the only model that ran with thinking on, so its 3/10 on S2T mixes "tool_choice is soft" with "thinking mode re-plans after the constraint". Splitting that into a second run with thinking off would tell you which one it is.
On failure mode 5: a grammar compile timeout returns HTTP 400, so an idempotent retry of the same request will usually fail the same way - 400 is a client-side schema problem that the server failed to compile. Retrying helps only if the schema is huge, and then the fix is shipping a smaller $defs graph or falling back to json_object for that call, not the retry. How are you deciding between retry and fallback in the gateway? A 429 or 503 gets a backoff, but a 400 grammar error probably should not burn the same retry budget.