fix: minja upper/lower filter fails on array type values#21342
Closed
gerstnr wants to merge 1 commit intoggml-org:masterfrom
Closed
fix: minja upper/lower filter fails on array type values#21342gerstnr wants to merge 1 commit intoggml-org:masterfrom
gerstnr wants to merge 1 commit intoggml-org:masterfrom
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
|
I'm going to close my PR this is better. |
Member
|
This is unfortunately still not quite right, I will make a PR with the proper fix. BTW, the template does not seem to correctly handle when |
Member
|
Proper jinja fix in #21370, at least from a compatibility viewpoint, the template still requires fixing IMO. |
Author
|
Thanks @CISC! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
When using Gemma 4 models with tool calling (tested Gemma-4-31B-It, unsloth gguf), requests to /v1/chat/completions or /v1/responses fail with a 500 error:
While executing FilterExpression at line 18, column 34 in source:
...if -%}
{%- if value['type'] | upper == 'STRING' -%}
^
Error: Unknown (built-in) filter 'upper' for type Array
This happens because Gemma 4's chat template (both the GGUF-embedded template and the new gemma4.jinja template from #21326) uses value['type'] | upper to check JSON Schema parameter types. Minja's value_array_t had no upper (or lower) method, causing the exception.
Reported in a comment on #21326: #21326 (comment)
Fix
Add upper and lower to value_array_t::get_builtins() in common/jinja/value.cpp, returning an empty string — the same fallback behavior already used by value_undefined_t.
Additional information
ch10299342 proposed fixing the template itself in #21326.
Valid, would preserve type-specific formatting for nullable params. The runtime fix is simpler and more defensive.
The two approaches are not mutually exclusive — a template fix could be applied on top.
Requirements