OpenRouter梳理三种可靠结构化输出方案
AI 总结
OpenRouter建议根据模型和端点支持情况,在严格 JSON Schema、强制工具调用和决策模型之间选择。其厂商自述测试使用24条杂乱客服消息覆盖九款结构化输出模型和 GLM 5.3 FlashX,严格 Schema 的216次回复中有209次匹配,7次失败均来自同一提供商。指南还建议启用必需参数约束、修复损坏的 JSON,并验证每次响应,因为部分端点仍会返回违反 Schema 的成功响应。
深度见解
该指南为开发者提供了一套实用兼容策略,用于应对不同提供商在 Schema、工具支持和约束执行方面的差异。
How to Get Structured Output from Any LLM: JSON Schema, Tool Calls, or a Decision Model
OpenRouter ·11/10/2026


When your code reads fields from a model’s reply, like an order ID or a refund amount, it expects clean JSON every time. Most of the time, it gets it. But now and then the model wraps the JSON in a code fence, adds a field you didn’t ask for, or sends a number as text, and your code breaks. If you use several models, one fix won’t cover them all, because each model and provider handles structured output in its own way.