Skip to content

Jinja Exception with the Qwen 3.5 models family #827

@k33g

Description

@k33g

With a qwen 2.5 model I can do this:

curl http://localhost:12434/engines/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
      "model": "qwen2.5:3B-F16",
      "stream": true,
      "messages": [
          {"role": "system", "content": "you are a helpful assistant."},
          {"role": "user", "content": "hello, how are you?"},
          {"role": "system", "content": "docker model runner rocks"},
          {"role": "user", "content": "what is docker model runner?"}
      ]
  }'

With a qwen 3.5 model, If I try the same:

curl http://localhost:12434/engines/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
      "model": "huggingface.co/unsloth/qwen3.5-4b-gguf:Q4_K_M",
      "stream": true,
      "messages": [
          {"role": "system", "content": "you are a helpful assistant."},
          {"role": "user", "content": "hello, how are you?"},
          {"role": "system", "content": "docker model runner rocks"},
          {"role": "user", "content": "what is docker model runner?"}
      ]
  }'

I get this error:

{"error":{"code":500,"message":"\n------------\nWhile executing CallExpression at line 85, column 32 in source:\n...first %}↵            {{- raise_exception('System message must be at the beginnin...\n                                           ^\nError: Jinja Exception: System message must be at the beginning.","type":"server_error"}}

the chat template contains this:

{%- if message.role == "system" %}
  {%- if not loop.first %}
    {{- raise_exception('System message must be at the beginning.') }}
  {%- endif %}

When the client sends a system message anywhere other than position [0] in the messages array, the template raises an exception and the server returns 500.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions