[PR #11372] [CLOSED] Add handling for non printable characters in tool arguments & tests. #12259

Closed
opened 2025-11-12 16:32:07 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/11372
Author: @CassidyMabey
Created: 7/11/2025
Status: Closed

Base: mainHead: nonprintablechar-removing-plus-tests


📝 Commits (1)

  • 1879bfe Add test cases and handling for nonprintable characters in the tool parser

📊 Changes

2 files changed (+40 additions, -10 deletions)

View changed files

📝 tools/tools.go (+15 -1)
📝 tools/tools_test.go (+25 -9)

📄 Description

When the AI generates large amounts of text and/or code blocks, they also produce large amounts of non printable characters. A mixture of this python doesn't like in the python Ollama framework which leads to issues which can't be resolved by the user. This is because of the way the AI calls the tool through the tool function interface where no parsing or removal of these non printable characters can occur before the tool is called. Then when python sees it as an argument it panics and throws a error.

I have provided some code below which should remove these characters before it is parsed into the tool as an argument.

I apologize if this is not correct but i at least wanted to try to do something to help fix it instead of just reporting the error itself. It passed all of the checks so thats a win. Let me know if i need to change anything else or if i have edited the wrong part of the codebase.

Thanks - Cassidy

ollama % go test ./...            

?   	github.com/ollama/ollama	[no test files]
ok  	github.com/ollama/ollama/api	(cached)
?   	github.com/ollama/ollama/api/examples/chat	[no test files]
?   	github.com/ollama/ollama/api/examples/generate	[no test files]
?   	github.com/ollama/ollama/api/examples/generate-streaming	[no test files]
?   	github.com/ollama/ollama/api/examples/multimodal	[no test files]
?   	github.com/ollama/ollama/api/examples/pull-progress	[no test files]
?   	github.com/ollama/ollama/app	[no test files]
?   	github.com/ollama/ollama/app/assets	[no test files]
# github.com/ollama/ollama/cmd.test
ld: warning: ignoring duplicate libraries: '-lobjc'
ok  	github.com/ollama/ollama/app/lifecycle	(cached)
?   	github.com/ollama/ollama/app/store	[no test files]
?   	github.com/ollama/ollama/app/tray	[no test files]
?   	github.com/ollama/ollama/app/tray/commontray	[no test files]
?   	github.com/ollama/ollama/auth	[no test files]
ok  	github.com/ollama/ollama/cmd	(cached)
?   	github.com/ollama/ollama/cmd/runner	[no test files]
ok  	github.com/ollama/ollama/convert	(cached)
?   	github.com/ollama/ollama/convert/sentencepiece	[no test files]
ok  	github.com/ollama/ollama/discover	(cached)
ok  	github.com/ollama/ollama/envconfig	(cached)
ok  	github.com/ollama/ollama/format	(cached)
?   	github.com/ollama/ollama/fs	[no test files]
ok  	github.com/ollama/ollama/fs/ggml	(cached)
# github.com/ollama/ollama/llm.test
ld: warning: ignoring duplicate libraries: '-lobjc'
ok  	github.com/ollama/ollama/fs/gguf	(cached)
ok  	github.com/ollama/ollama/fs/util/bufioutil	(cached)
ok  	github.com/ollama/ollama/kvcache	(cached)
ok  	github.com/ollama/ollama/llama	(cached)
?   	github.com/ollama/ollama/llama/llama.cpp/common	[no test files]
?   	github.com/ollama/ollama/llama/llama.cpp/src	[no test files]
?   	github.com/ollama/ollama/llama/llama.cpp/tools/mtmd	[no test files]
ok  	github.com/ollama/ollama/llm	(cached)
?   	github.com/ollama/ollama/logutil	[no test files]
?   	github.com/ollama/ollama/ml	[no test files]
?   	github.com/ollama/ollama/ml/backend	[no test files]
?   	github.com/ollama/ollama/ml/backend/ggml	[no test files]
?   	github.com/ollama/ollama/ml/backend/ggml/ggml/src	[no test files]
?   	github.com/ollama/ollama/ml/backend/ggml/ggml/src/ggml-blas	[no test files]
?   	github.com/ollama/ollama/ml/backend/ggml/ggml/src/ggml-cpu	[no test files]
?   	github.com/ollama/ollama/ml/backend/ggml/ggml/src/ggml-cpu/llamafile	[no test files]
?   	github.com/ollama/ollama/ml/backend/ggml/ggml/src/ggml-metal	[no test files]
?   	github.com/ollama/ollama/ml/nn	[no test files]
?   	github.com/ollama/ollama/ml/nn/fast	[no test files]
?   	github.com/ollama/ollama/ml/nn/rope	[no test files]
ok  	github.com/ollama/ollama/model	(cached)
ok  	github.com/ollama/ollama/model/imageproc	(cached)
?   	github.com/ollama/ollama/model/input	[no test files]
?   	github.com/ollama/ollama/model/models	[no test files]
?   	github.com/ollama/ollama/model/models/gemma2	[no test files]
?   	github.com/ollama/ollama/model/models/gemma3	[no test files]
?   	github.com/ollama/ollama/model/models/gemma3n	[no test files]
?   	github.com/ollama/ollama/model/models/llama	[no test files]
ok  	github.com/ollama/ollama/model/models/llama4	(cached)
?   	github.com/ollama/ollama/model/models/mistral3	[no test files]
ok  	github.com/ollama/ollama/model/models/mllama	(cached)
?   	github.com/ollama/ollama/model/models/qwen2	[no test files]
?   	github.com/ollama/ollama/model/models/qwen25vl	[no test files]
?   	github.com/ollama/ollama/model/models/qwen3	[no test files]
# github.com/ollama/ollama/runner/llamarunner.test
ld: warning: ignoring duplicate libraries: '-lobjc'
# github.com/ollama/ollama/runner/ollamarunner.test
ld: warning: ignoring duplicate libraries: '-lobjc'
ok  	github.com/ollama/ollama/openai	(cached)
ok  	github.com/ollama/ollama/parser	(cached)
?   	github.com/ollama/ollama/progress	[no test files]
?   	github.com/ollama/ollama/readline	[no test files]
?   	github.com/ollama/ollama/runner	[no test files]
ok  	github.com/ollama/ollama/runner/common	(cached)
ok  	github.com/ollama/ollama/runner/llamarunner	(cached)
ok  	github.com/ollama/ollama/runner/ollamarunner	(cached)
ok  	github.com/ollama/ollama/sample	(cached)
# github.com/ollama/ollama/server.test
ld: warning: ignoring duplicate libraries: '-lobjc'
ok  	github.com/ollama/ollama/server	(cached)
ok  	github.com/ollama/ollama/server/internal/cache/blob	(cached)
ok  	github.com/ollama/ollama/server/internal/client/ollama	(cached)
?   	github.com/ollama/ollama/server/internal/internal/backoff	[no test files]
ok  	github.com/ollama/ollama/server/internal/internal/names	(cached)
ok  	github.com/ollama/ollama/server/internal/internal/stringsx	(cached)
?   	github.com/ollama/ollama/server/internal/internal/syncs	[no test files]
?   	github.com/ollama/ollama/server/internal/manifest	[no test files]
ok  	github.com/ollama/ollama/server/internal/registry	(cached)
?   	github.com/ollama/ollama/server/internal/testutil	[no test files]
ok  	github.com/ollama/ollama/template	(cached)
ok  	github.com/ollama/ollama/thinking	(cached)
ok  	github.com/ollama/ollama/tools	(cached)
?   	github.com/ollama/ollama/types/errtypes	[no test files]
ok  	github.com/ollama/ollama/types/model	(cached)
?   	github.com/ollama/ollama/types/syncmap	[no test files]
?   	github.com/ollama/ollama/version	[no test files]


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/11372 **Author:** [@CassidyMabey](https://github.com/CassidyMabey) **Created:** 7/11/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `nonprintablechar-removing-plus-tests` --- ### 📝 Commits (1) - [`1879bfe`](https://github.com/ollama/ollama/commit/1879bfe4a58ae7d3149b0ac52606014e0dd3877a) Add test cases and handling for nonprintable characters in the tool parser ### 📊 Changes **2 files changed** (+40 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `tools/tools.go` (+15 -1) 📝 `tools/tools_test.go` (+25 -9) </details> ### 📄 Description When the AI generates large amounts of text and/or code blocks, they also produce large amounts of non printable characters. A mixture of this python doesn't like in the python Ollama framework which leads to issues which can't be resolved by the user. This is because of the way the AI calls the tool through the tool function interface where no parsing or removal of these non printable characters can occur before the tool is called. Then when python sees it as an argument it panics and throws a error. I have provided some code below which should remove these characters before it is parsed into the tool as an argument. I apologize if this is not correct but i at least wanted to try to do something to help fix it instead of just reporting the error itself. It passed all of the checks so thats a win. Let me know if i need to change anything else or if i have edited the wrong part of the codebase. Thanks - Cassidy ``` ollama % go test ./... ? github.com/ollama/ollama [no test files] ok github.com/ollama/ollama/api (cached) ? github.com/ollama/ollama/api/examples/chat [no test files] ? github.com/ollama/ollama/api/examples/generate [no test files] ? github.com/ollama/ollama/api/examples/generate-streaming [no test files] ? github.com/ollama/ollama/api/examples/multimodal [no test files] ? github.com/ollama/ollama/api/examples/pull-progress [no test files] ? github.com/ollama/ollama/app [no test files] ? github.com/ollama/ollama/app/assets [no test files] # github.com/ollama/ollama/cmd.test ld: warning: ignoring duplicate libraries: '-lobjc' ok github.com/ollama/ollama/app/lifecycle (cached) ? github.com/ollama/ollama/app/store [no test files] ? github.com/ollama/ollama/app/tray [no test files] ? github.com/ollama/ollama/app/tray/commontray [no test files] ? github.com/ollama/ollama/auth [no test files] ok github.com/ollama/ollama/cmd (cached) ? github.com/ollama/ollama/cmd/runner [no test files] ok github.com/ollama/ollama/convert (cached) ? github.com/ollama/ollama/convert/sentencepiece [no test files] ok github.com/ollama/ollama/discover (cached) ok github.com/ollama/ollama/envconfig (cached) ok github.com/ollama/ollama/format (cached) ? github.com/ollama/ollama/fs [no test files] ok github.com/ollama/ollama/fs/ggml (cached) # github.com/ollama/ollama/llm.test ld: warning: ignoring duplicate libraries: '-lobjc' ok github.com/ollama/ollama/fs/gguf (cached) ok github.com/ollama/ollama/fs/util/bufioutil (cached) ok github.com/ollama/ollama/kvcache (cached) ok github.com/ollama/ollama/llama (cached) ? github.com/ollama/ollama/llama/llama.cpp/common [no test files] ? github.com/ollama/ollama/llama/llama.cpp/src [no test files] ? github.com/ollama/ollama/llama/llama.cpp/tools/mtmd [no test files] ok github.com/ollama/ollama/llm (cached) ? github.com/ollama/ollama/logutil [no test files] ? github.com/ollama/ollama/ml [no test files] ? github.com/ollama/ollama/ml/backend [no test files] ? github.com/ollama/ollama/ml/backend/ggml [no test files] ? github.com/ollama/ollama/ml/backend/ggml/ggml/src [no test files] ? github.com/ollama/ollama/ml/backend/ggml/ggml/src/ggml-blas [no test files] ? github.com/ollama/ollama/ml/backend/ggml/ggml/src/ggml-cpu [no test files] ? github.com/ollama/ollama/ml/backend/ggml/ggml/src/ggml-cpu/llamafile [no test files] ? github.com/ollama/ollama/ml/backend/ggml/ggml/src/ggml-metal [no test files] ? github.com/ollama/ollama/ml/nn [no test files] ? github.com/ollama/ollama/ml/nn/fast [no test files] ? github.com/ollama/ollama/ml/nn/rope [no test files] ok github.com/ollama/ollama/model (cached) ok github.com/ollama/ollama/model/imageproc (cached) ? github.com/ollama/ollama/model/input [no test files] ? github.com/ollama/ollama/model/models [no test files] ? github.com/ollama/ollama/model/models/gemma2 [no test files] ? github.com/ollama/ollama/model/models/gemma3 [no test files] ? github.com/ollama/ollama/model/models/gemma3n [no test files] ? github.com/ollama/ollama/model/models/llama [no test files] ok github.com/ollama/ollama/model/models/llama4 (cached) ? github.com/ollama/ollama/model/models/mistral3 [no test files] ok github.com/ollama/ollama/model/models/mllama (cached) ? github.com/ollama/ollama/model/models/qwen2 [no test files] ? github.com/ollama/ollama/model/models/qwen25vl [no test files] ? github.com/ollama/ollama/model/models/qwen3 [no test files] # github.com/ollama/ollama/runner/llamarunner.test ld: warning: ignoring duplicate libraries: '-lobjc' # github.com/ollama/ollama/runner/ollamarunner.test ld: warning: ignoring duplicate libraries: '-lobjc' ok github.com/ollama/ollama/openai (cached) ok github.com/ollama/ollama/parser (cached) ? github.com/ollama/ollama/progress [no test files] ? github.com/ollama/ollama/readline [no test files] ? github.com/ollama/ollama/runner [no test files] ok github.com/ollama/ollama/runner/common (cached) ok github.com/ollama/ollama/runner/llamarunner (cached) ok github.com/ollama/ollama/runner/ollamarunner (cached) ok github.com/ollama/ollama/sample (cached) # github.com/ollama/ollama/server.test ld: warning: ignoring duplicate libraries: '-lobjc' ok github.com/ollama/ollama/server (cached) ok github.com/ollama/ollama/server/internal/cache/blob (cached) ok github.com/ollama/ollama/server/internal/client/ollama (cached) ? github.com/ollama/ollama/server/internal/internal/backoff [no test files] ok github.com/ollama/ollama/server/internal/internal/names (cached) ok github.com/ollama/ollama/server/internal/internal/stringsx (cached) ? github.com/ollama/ollama/server/internal/internal/syncs [no test files] ? github.com/ollama/ollama/server/internal/manifest [no test files] ok github.com/ollama/ollama/server/internal/registry (cached) ? github.com/ollama/ollama/server/internal/testutil [no test files] ok github.com/ollama/ollama/template (cached) ok github.com/ollama/ollama/thinking (cached) ok github.com/ollama/ollama/tools (cached) ? github.com/ollama/ollama/types/errtypes [no test files] ok github.com/ollama/ollama/types/model (cached) ? github.com/ollama/ollama/types/syncmap [no test files] ? github.com/ollama/ollama/version [no test files] ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-12 16:32:07 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama-ollama#12259