結構化輸出與 Function Calling 壓力測試:201 次呼叫揭示 5 種生產環境故障模式
Structured Output & Function Calling Under Stress: 5 Production Failure Modes Across 201 Calls
研究以 4 個模型進行 201 次即時呼叫測試,揭示結構化輸出與 Function Calling 在生產環境中的 5 種故障模式。qwen3.8-max 在全部測試中成功;kimi-k3.1-pro 的工具路由提示測試 20 次全數違規,但指定 tool_choice=query_inventory 後 10 次全數成功。
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.
來源:DEV Community · dev.to