ollama - 💡(How to fix) Fix gemma4:26b / 31b issues with structured output [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
ollama/ollama#15576Fetched 2026-04-16 06:36:06
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
labeled ×1
RAW_BUFFERClick to expand / collapse

What is the issue?

Issue:

gemma4:26b / 31b has issues with structured output where in the following example it says there is no context.

Summary:

A RAG solution has a tool calling node that calls tools to retrieve documents (context) that is then used by a final answer node to provide a structured output citing the used documents.

The tool calls are executed correctly, the tool response includes context_id: xxx content: This document blah

However the final node with structured output always returns a response where the model can't find any context. This is not the case when using other models such as nemo, gpt-oss, qwen, deepseek etc

Simplified Example:

class CitedAnswer(BaseModel): """ Structured answer to a user question. """ content: str = Field( description=( "The final answer to the user's question based ONLY on the supplied context. " ) ) context_id: List[str] = Field( description=( " Cite ONLY the context_id values from the provided sources that were explicitly used in forming the answer" ) )

final_model.format= CitedAnswer.model_json_schema()

Relevant log output

OS

No response

GPU

No response

CPU

No response

Ollama version

No response

extent analysis

TL;DR

The issue might be resolved by verifying that the context_id values returned by the tool calls are correctly passed to the final answer node and match the expected format.

Guidance

  • Review the implementation of the final answer node to ensure it correctly handles the context_id values returned by the tool calls.
  • Verify that the context_id values are correctly formatted and match the expected format in the CitedAnswer model.
  • Check the documentation of the RAG solution and the final answer node to ensure that the context_id values are being used as expected.
  • Test the final answer node with a simplified example to isolate the issue and verify that it works as expected with other models.

Example

No code snippet is provided as the issue lacks specific implementation details.

Notes

The issue might be specific to the gemma4:26b / 31b model, and the solution may not apply to other models. Additional information about the RAG solution, the tool calls, and the final answer node implementation would be helpful to provide a more accurate solution.

Recommendation

Apply workaround: Verify that the context_id values are correctly passed and formatted, and test the final answer node with a simplified example to isolate the issue. This is because the issue seems to be specific to the gemma4:26b / 31b model, and a workaround might be necessary to resolve the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING