DEV Community

王果ai
王果ai

Posted on

Structured Output & Function Calling Under Stress: 5 Production Failure Modes Across 201 Calls

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 = 95600 integer cents), tested prompt-only (S1, n=10) and with response_format: {"type": "json_object"} (S1R, n=10).
  • S2 / S2T: 6-tool routing where the prompt mandates query_inventory as step 1, tested prompt-only (S2, n=20) and with explicit tool_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

  1. Perfect JSON, Wrong Arithmetic (deepseek-v4-pro on S1/S1R): 7 of 8 S1 failures returned valid JSON with "payable_cents": 95000 instead of 95600. Adding json_object eliminated Markdown fences (S1R), but 5/10 still failed arithmetic (95000, 104600, 95700, 93000). Schema validation cannot catch business-logic math errors—always recompute totals in code.
  2. "Reasonable Detours" (kimi-k3.1-pro 20/20, deepseek-v4-pro 9/20 on S2): Instead of calling query_inventory first as instructed, kimi-k3.1-pro called query_order every single time ("to verify the SKU first"). Reasonable logic, 100% workflow violation. Enforcing tool_choice fixed kimi-k3.1-pro to 10/10.
  3. Replying to the User Instead of Calling a Tool (deepseek-v4-pro 4/20, glm-5.3-prime 1/20): When uncertain, models fall back to conversational clarification. Your Agent state machine must explicitly handle a no tool_calls branch.
  4. tool_choice Is Not Always Hard-Enforced (glm-5.3-prime 3/10 on S2T): Even with tool_choice=query_inventory explicitly set, glm-5.3-prime called query_order twice and replied "好的" (no tool call) once. Never treat tool_choice as a 100% guarantee without code-level assertion.
  5. Transient Server-Side Grammar Timeout (deepseek-v4-pro 1/10 on S2T): One tool_choice request 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_choice as a hint and assert tool_calls[0].function.name in code.
  • ☐ Handle no tool_calls explicitly in your state machine.
  • ☐ Extract raw quantities/prices with the LLM, but compute financial totals in deterministic code.
  • ☐ Align enable_thinking flags 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

Top comments (0)