ollama - 💡(How to fix) Fix Not escaped output from model causing XML syntax error [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
ollama/ollama#15574Fetched 2026-04-16 06:36:09
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
1
Author
Participants
Timeline (top)
labeled ×1

Error Message

When output from model isn't escaped, contains i.e < and/or > chars, then causing Ollama XML syntax error. {"error":"XML syntax error on line 12: element \u003cparameter\u003e closed by \u003c/function\u003e"} Not sure, if any output from model, even not escaped should causing error on Ollama side.

Code Example

curl -X POST http://localhost:11434/api/chat \
-H "Content-Type: application/json" \
-d '{
  "model": "qwen3.5:9b",
  "stream": false,
  "messages": [
    {
      "role": "user",
      "content": "Spusť tento kód:\n10 MODE2\n20 FORV=0TO255\n30 FORU=0TO159\n40 x=U/64-1:y=V/128-1.4\n50 z=1/SQR(x*x+y*y+1):x=x*z:y=y*z\n60 X=0:Y=.4:Z=-2\n70 P=-Y*y-Z*z:i=x*P:j=Y+y*P:k=Z+z*P:C=i*i+j*j+k*k\n80 IFC<1w=P-SQR(1-C):X=w*x:Y=Y+w*y:Z=Z+w*z:D=2*(X*x+Y*y+Z*z):x=x-D*X:y=y-D*Y:z=z-D*Z\n90 t=-(Y-1.5*SGNy)/y:u=X+x*t:v=Z+z*t\n100 S=-u*.5+v*.8:T=u*.8+v*.5\n110 GCOL0,15AND(INT(T*8)+8*INTS)\n120 PLOT69,U*8,V*4\n130 NEXT,\n140 REPEAT\n150 VDU19,U,0;0;19,U+1,4;0;19,U+2,6;0;19,U+7,7;0;19,U+8,3;0;19,U+9,1;0;5\n160 U=U+.5\n170 UNTIL0\n180 REM"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "run_microbasic",
        "description": "Spustí kód v jazyce BBC Micro Basic v emulátoru, pořídí krátký videozáznam běhu programu a vrátí výsledek.",
        "parameters": {
          "type": "object",
          "properties": {
            "source": {
              "type": "string",
              "description": "Zdrojový kód v MicroBasicu ke spuštění."
            }
          },
          "required": ["source"]
        }
      }
    }
  ]
}'

---

{"error":"XML syntax error on line 12: element \u003cparameter\u003e closed by \u003c/function\u003e"}

---
RAW_BUFFERClick to expand / collapse

What is the issue?

When output from model isn't escaped, contains i.e < and/or > chars, then causing Ollama XML syntax error.

Code to replicate bug:

curl -X POST http://localhost:11434/api/chat \
-H "Content-Type: application/json" \
-d '{
  "model": "qwen3.5:9b",
  "stream": false,
  "messages": [
    {
      "role": "user",
      "content": "Spusť tento kód:\n10 MODE2\n20 FORV=0TO255\n30 FORU=0TO159\n40 x=U/64-1:y=V/128-1.4\n50 z=1/SQR(x*x+y*y+1):x=x*z:y=y*z\n60 X=0:Y=.4:Z=-2\n70 P=-Y*y-Z*z:i=x*P:j=Y+y*P:k=Z+z*P:C=i*i+j*j+k*k\n80 IFC<1w=P-SQR(1-C):X=w*x:Y=Y+w*y:Z=Z+w*z:D=2*(X*x+Y*y+Z*z):x=x-D*X:y=y-D*Y:z=z-D*Z\n90 t=-(Y-1.5*SGNy)/y:u=X+x*t:v=Z+z*t\n100 S=-u*.5+v*.8:T=u*.8+v*.5\n110 GCOL0,15AND(INT(T*8)+8*INTS)\n120 PLOT69,U*8,V*4\n130 NEXT,\n140 REPEAT\n150 VDU19,U,0;0;19,U+1,4;0;19,U+2,6;0;19,U+7,7;0;19,U+8,3;0;19,U+9,1;0;5\n160 U=U+.5\n170 UNTIL0\n180 REM"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "run_microbasic",
        "description": "Spustí kód v jazyce BBC Micro Basic v emulátoru, pořídí krátký videozáznam běhu programu a vrátí výsledek.",
        "parameters": {
          "type": "object",
          "properties": {
            "source": {
              "type": "string",
              "description": "Zdrojový kód v MicroBasicu ke spuštění."
            }
          },
          "required": ["source"]
        }
      }
    }
  ]
}'

output:

{"error":"XML syntax error on line 12: element \u003cparameter\u003e closed by \u003c/function\u003e"}

Not sure, if any output from model, even not escaped should causing error on Ollama side.

Relevant log output

OS

Linux

GPU

AMD

CPU

AMD

Ollama version

0.20.5

extent analysis

TL;DR

The issue can be resolved by properly escaping the output from the model to prevent XML syntax errors.

Guidance

  • The error message indicates an XML syntax error caused by unescaped characters (< and >) in the output from the model.
  • To fix this, the output from the model should be escaped to prevent it from being interpreted as XML.
  • The run_microbasic function is likely generating output that contains these unescaped characters, which is then being passed to Ollama and causing the error.
  • Verify that the output from the model is being properly escaped before being passed to Ollama.

Example

No code snippet is provided as the issue is more related to the data being passed rather than the code itself.

Notes

The issue seems to be related to the interaction between the run_microbasic function and Ollama, and the exact solution may depend on the specifics of how these components are integrated.

Recommendation

Apply workaround: Properly escape the output from the model to prevent XML syntax errors, as this is the most direct way to address the issue described.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING