HTTP models ignore `includeSchemaInPrompt`, so structured output fails on servers that don't enforce schemas
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- swift
调研方向
Start by tracing how includeSchemaInPrompt is handled in the existing MLX, llama.cpp, and Core ML models, then compare that with the Ollama, OpenAI, Open Responses, Anthropic, and Gemini request paths. The issue describes adding schema instructions to the last transcript entry before provider message conversion, while retaining each server's schema field. Done means streaming, non-streaming, and post-tool-round tests cover every HTTP model; a proposed fix and tests are already available in a linked branch.
由索引模型根据 Issue 内容生成。
描述
Summary
The HTTP language models send a response schema only to the server (format, response_format, output_config, responseSchema), and ignore includeSchemaInPrompt. When the server doesn't enforce the schema, the model never sees it, answers in prose, and respond(generating:) throws typeMismatch.
Ollama's cloud models are one such server: they accept format and ignore it (ollama/ollama#12362). Some OpenAI-compatible servers do the same with response_format.
To reproduce
@Generable
struct Greeting {
let text: String
}
let session = LanguageModelSession(model: OllamaLanguageModel(model: "deepseek-v4.1-flash:cloud"))
let greeting = try await session.respond(to: "Say hello.", generating: Greeting.self)
// Throws DecodingError.typeMismatch: the model answered in plain text.
The same code works with a local model such as qwen3:8b, because the local Ollama server enforces format.
Cause
includeSchemaInPrompt is true by default. MLX, llama.cpp, Core ML and Foundation Models honor it by saying the schema in the prompt. Ollama, OpenAI, Open Responses, Anthropic and Gemini accept it but never use it.
Proposed fix
Make the HTTP models honor includeSchemaInPrompt the way the local ones do:
- When
includeSchemaInPromptistrueand the response type isn'tString, each HTTP model (Ollama, OpenAI, Open Responses, Anthropic, Gemini) appends the schema instructions as a text segment to the last prompt entry of the request's transcript, before converting it to the provider's messages. - The schema is still sent to the server as today (
format,response_format,output_config,responseSchema). - The private
schemaPrompt(for:)copies in MLX, llama.cpp and Core ML become one sharedGenerationSchema.schemaPrompt(), which states the inlined schema.
A branch with this and tests for every HTTP model (streaming, non-streaming, after a tool round) is ready as a PR: akbashev:fix/schema-in-prompt.
Still a problem after the fix
Servers that enforce a schema constrain decoding, so the model can only produce valid output. Servers that don't, like Ollama Cloud (ollama/ollama#12362), let it write anything: the schema in the prompt is only an instruction, and models sometimes ignore it, especially after tool calls. With beam:cloud, about half of the answers after several tool calls were still prose, so typeMismatch.
- 主要语言
- Swift
- 星标
- 959
- 派生
- 99
- 平均合并
- 1 天 10 小时
- 30 天内合并 PR
- 70
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
huggingface/AnyLanguageModel 的其他 Issue
-
难度 5/5 一周以上 新手友好度 35/100
huggingface/AnyLanguageModel#360 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 25/100
huggingface/AnyLanguageModel#359 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 18/100
huggingface/AnyLanguageModel#328 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 62/100
huggingface/AnyLanguageModel#327 ·
维护者通常 1 天内回复
-
Support the Gemini Interactions API in GeminiLanguageModel可能重新可做 @rizwankce 于 17 天前认领,目前没有进行中的 PR。 未关闭
难度 5/5 一周以上 新手友好度 45/100
huggingface/AnyLanguageModel#302 · 2 条评论 ·
维护者通常 1 天内回复
查看 huggingface/AnyLanguageModel 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 65/100
jellyfin/Swiftfin#2388 · 1 条评论 ·
维护者通常 1 天内回复
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P2
难度 2/5 1-3 小时 新手友好度 74/100
openclaw/openclaw#183929 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
-
area: browser area: cli
难度 2/5 1-3 小时 新手友好度 76/100
manaflow-ai/cmux#25105 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
glushchenko/fsnotes#2045 ·