Skip to content

fix: strip null values from tool call args to prevent Jinja template errors#12236

Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/strip-null-mode-jinja-template-error
Draft

fix: strip null values from tool call args to prevent Jinja template errors#12236
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/strip-null-mode-jinja-template-error

Conversation

@roomote-v0
Copy link
Copy Markdown
Contributor

@roomote-v0 roomote-v0 Bot commented Apr 30, 2026

This PR attempts to address Issue #12233.

Problem

Local models using Jinja chat templates (e.g. llama.cpp, Ollama) cannot handle null values in tool call arguments, causing:

Chat template error: Runtime error: Cannot convert value of type Optional<Any> to Jinja Value

This happens because the ask_followup_question tool schema requires mode with type: ["string", "null"] and strict: true, forcing models to output "mode": null. When this tool call appears in conversation history and gets serialized back to the model, the Jinja template fails on the null value.

Changes

  1. Tool schema (ask_followup_question.ts): Removed strict: true and made mode optional (not required), following the same pattern as read_command_output. Updated examples to omit mode instead of using null.

  2. Tool execution (AskFollowupQuestionTool.ts): Strip null mode values when building the follow-up JSON to prevent nulls from reaching the conversation history.

  3. Message serialization (openai-format.ts): Strip null values from ALL tool call arguments during OpenAI message conversion as a general safety net. This prevents any tool from inadvertently sending null values to Jinja templates.

  4. Tests: Added tests verifying null mode stripping in both tool execution and message serialization.

Feedback and guidance are welcome.

Interactively review PR in Roo Code Cloud

…errors

Local models using Jinja chat templates (e.g. llama.cpp, Ollama) cannot
handle null values in tool call arguments, causing "Cannot convert value
of type Optional<Any> to Jinja Value" errors when selecting follow-up
answers.

Changes:
- Remove strict mode from ask_followup_question tool definition and make
  mode optional (not required), matching the read_command_output pattern
- Update examples to omit mode instead of using null
- Strip null mode values when building follow_up JSON in the tool
- Strip null values from all tool call arguments during OpenAI message
  serialization as a general safety net
- Add tests for null stripping behavior

Addresses #12233
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant