Fix chat template crash when tool property has no explicit type

#4

Bug

chat_template.jinja calls value['type'] | upper on every property in a tool's
parameters.properties, in four places inside the format_parameters macro.

JSON Schema (and the OpenAI Chat Completions API) both allow a property without an
explicit type field — a property with only a description is valid. Several popular
OpenAI-compatible clients emit schemas like that (for example, agent frameworks such
as Hermes and OpenClaw).

When such a schema is passed through Gemma's chat template, Jinja raises:

Cannot apply filter "upper" to type: UndefinedValue

and generation fails before any tokens are produced.

Minimal repro

curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "onnx-community/gemma-4-E4B-it-ONNX",
    "messages": [{"role":"user","content":"hi"}],
    "tools": [{"type":"function","function":{"name":"test","parameters":{
      "type":"object","properties":{"a":{"description":"a value"}}
    }}}],
    "max_tokens": 10
  }'

(Reproduced against transformers.js inference; the same template is loaded by
@huggingface/transformers under Node.)

Fix

Default the missing type to 'string' before applying | upper. String is the most
common and safest default for a described but untyped property. Same fix pattern, four
call sites:

- value['type'] | upper
+ (value['type'] | default('string')) | upper

This does not change behavior for any property that already sets type.

Scope

  • Only touches format_parameters in chat_template.jinja.
  • Same fix applies to onnx-community/gemma-4-E2B-it-ONNX (identical template) — a
    companion PR is opened there.

@NERDDISCO were you able to finetune and create to onnx, any example would be helpful

Ready to merge
This branch is ready to get merged automatically.

Sign up or log in to comment