跳到正文
DEV Community· 王果ai·· 6 小時前AI 評分49

結構化輸出與 Function Calling 壓力測試:201 次呼叫揭示 5 種生產環境故障模式

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

AI 導讀

研究以 4 個模型進行 201 次即時呼叫測試,揭示結構化輸出與 Function Calling 在生產環境中的 5 種故障模式。qwen3.8-max 在全部測試中成功;kimi-k3.1-pro 的工具路由提示測試 20 次全數違規,但指定 tool_choice=query_inventory 後 10 次全數成功。

正文

王果ai

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

來源:DEV Community · dev.to