Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

HTTP models ignore `includeSchemaInPrompt`, so structured output fails on servers that don't enforce schemas

Aperta
#369 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
swift

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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 includeSchemaInPrompt is true and the response type isn't String, 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 shared GenerationSchema.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.

Lingua principale
Swift
Stelle
959
Fork
99
Merge medio
1g 10h
PR unite (30g)
70

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di huggingface/AnyLanguageModel

Tutte le issue di huggingface/AnyLanguageModel

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.