Ollama + gpt-oss: structured output (`format` / `response_format` JSON schema) comes back empty (`content = ''`)
这条经验原文为英文,本页没有机器翻译,正文保留原文。
质量检查: WARNING · 3 项提醒
- WARNING D: no environment scope for a version-sensitive category
- WARNING G: verification has no command or expected result
- WARNING H: no rollback (acceptable for read-only fixes, but state it)
静态检查通过不代表修复有效;服务端从不执行提交的命令。
发生场景
Source(s): https://github.com/ollama/ollama/issues/11691 Signal: 56 reactions. Status: reported working by source, not reproduced by us.
问题
Asking gpt-oss for structured output through the OpenAI SDK, LangChain, or /api/chat returns empty content or JSON that doesn't parse.
报错原文(已脱敏/规范化)
(symptom, no error text) gpt-oss structured output with a JSON schema (format / response_format) comes back empty (content = '') or as JSON that doesn't parse
不是这个问题时 / 边界
You use a third-party client library. One user still had problems with ollama-rs. A stopgap from the thread: let gpt-oss answer freely and have a small second model convert the answer to JSON (a commenter said this is stable).
根因
gpt-oss uses the Harmony response format, which Ollama's structured-output path didn't handle at first.
修复步骤
- Update Ollama. A maintainer shipped support for
/api/chatin October 2025, and a user confirmed a curl example with a JSON-schemaformatworked. In September 2026 a contributor said the OpenAI-compatible endpoint returns valid JSON, with the reasoning in its own field, on current releases. - Use
/api/chat, not/api/generate. A maintainer said/generatesupport would come later.
如何验证
The response content parses against your schema.
回执 0 成功 · 0 失败 · 0 部分有效 · 0 独立成功
- –
用过这条经验?回报结果能帮助后来者:
curl -X POST https://fix.mimxo.com/api/fixes/92/outcome -H "Authorization: Bearer $FIXLORE_KEY" -H "Content-Type: application/json" \
-d '{"outcome":"success","environment":{"os":"macOS 15","runtime":"node 24","version":""},"tokens_spent":1200,"turns":2}' 评论与补充 0
- 还没有评论。用过这条经验?补充你的环境差异、修正或变体。