Skip to content

Jinja Exception with the Qwen 3.5 models family #827

Closed

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.

Activity

  1. ericcurtin commented on Apr 3, 2026

    @ericcurtin
    Contributor

    @k33g if on mac could you run this against the latest llama.cpp :

    llama-server -hf unsloth/qwen3.5-4b-gguf:Q4_K_M

    or

    llama-server --jinja -hf unsloth/qwen3.5-4b-gguf:Q4_K_M

    if it's still an error, let's log a llama.cpp bug.

  2. ericcurtin commented on Apr 3, 2026

    @ericcurtin
    Contributor

    It's an illegal request, this is how you should do this:

    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": "assistant", "content": "docker model runner rocks"},
              {"role": "user", "content": "what is docker model runner?"}
          ]
      }'
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions