From 55bf493f44e3f1bbe2055360e6892d7ff640b686 Mon Sep 17 00:00:00 2001 From: Till JS Date: Thu, 9 Apr 2026 19:44:13 +0200 Subject: [PATCH] fix(api): set supportsStructuredOutputs=true on mana-llm provider MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit generateObject() in the AI SDK falls back to a tool-call mode when the provider doesn't advertise structured-output support — and tool calling through Ollama isn't reliable enough that the schema-validation step passes. The response was failing with 'No object generated: response did not match schema' even though the underlying mana-llm + Ollama roundtrip works correctly when called with response_format directly (verified via curl). Set supportsStructuredOutputs:true on the createOpenAICompatible factory so the AI SDK uses response_format json_schema mode. mana-llm already routes that to Ollama's native format field thanks to the companion fix in services/mana-llm/src/providers/ollama.py — verified end-to-end with the MealAnalysisSchema and Gemma 3 4B. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/api/src/modules/nutriphi/routes.ts | 8 ++++++++ apps/api/src/modules/planta/routes.ts | 2 ++ 2 files changed, 10 insertions(+) diff --git a/apps/api/src/modules/nutriphi/routes.ts b/apps/api/src/modules/nutriphi/routes.ts index 8b4666fd4..b4fa7b152 100644 --- a/apps/api/src/modules/nutriphi/routes.ts +++ b/apps/api/src/modules/nutriphi/routes.ts @@ -45,6 +45,14 @@ const llm = createOpenAICompatible({ // src/main.py:125). The AI SDK's openai-compatible adapter appends // /chat/completions to baseURL, so baseURL ends in /v1. baseURL: `${LLM_URL}/v1`, + // Tell the AI SDK that mana-llm honours OpenAI-style strict + // json_schema response_format. Without this, generateObject() falls + // back to a tool-call mode that Ollama-backed models don't support + // reliably and the response fails to validate against the Zod schema. + // mana-llm's Ollama provider translates response_format → Ollama's + // native `format` field (services/mana-llm/src/providers/ollama.py) + // so this is honoured end-to-end. + supportsStructuredOutputs: true, }); const ANALYSIS_PROMPT = `Du bist ein Ernährungsexperte. Analysiere die Mahlzeit und gib strukturierte Nährwertdaten zurück. Schätze realistische Portionsgrößen und Kalorien. Antworte auf Deutsch.`; diff --git a/apps/api/src/modules/planta/routes.ts b/apps/api/src/modules/planta/routes.ts index 40ed906a1..d61064790 100644 --- a/apps/api/src/modules/planta/routes.ts +++ b/apps/api/src/modules/planta/routes.ts @@ -28,6 +28,8 @@ const VISION_MODEL = process.env.VISION_MODEL || 'ollama/gemma3:4b'; const llm = createOpenAICompatible({ name: 'mana-llm', baseURL: `${LLM_URL}/v1`, + // See nutriphi/routes.ts for the rationale on this flag. + supportsStructuredOutputs: true, }); const IDENTIFICATION_PROMPT = `Du bist ein Pflanzenexperte. Analysiere das Pflanzenfoto und liefere eine strukturierte Identifikation mit lateinischem Namen, deutschen Trivialnamen, Pflegehinweisen und einer Gesundheitseinschätzung. Antworte auf Deutsch.`;