[PR #2371] [Engine] read Python-style tool argument literals (True, None) by the declared type, whole and streamed #4011

Open
opened 2026-11-07 15:32:27 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2371
Author: @anstaendig
Created: 10/14/2026
Status: 🔄 Open

Base: main ← Head: fix/tool-argument-schema-coercion


📝 Commits (1)

  • faab1b4 serve: read Python-style tool argument literals (True, None, +10) by the declared type, whole and streamed

📊 Changes

3 files changed (+212 additions, -10 deletions)

View changed files

📝 serve/frontend.py (+47 -10)
📝 serve/test_server.py (+22 -0)
➕ serve/test_tool_argument_types.py (+143 -0)

📄 Description

Problem and result

The model sometimes writes tool arguments Python-style, for example <parameter=onlyMainContent>True</parameter> or <parameter=unlock>False</parameter>. That is not JSON, so coerce_value passed the text through and a boolean parameter reached the client as the string "True" / "False" (truthy either way). Strict tool servers reject it (expected boolean, received string, reported above with firecrawl-mcp, and with opencode on 0.2.2 011c9e6: 12 of 55 boolean arguments).

Reproduced on current main (c62d5e3a) with OutputParser(stream_tools=True) and a tool declaring onlyMainContent: {"type": "boolean"}:

  • before: streamed tool_args and the final call both give {"url": "https://x.y", "onlyMainContent": "True"}
  • after: both give {"url": "https://x.y", "onlyMainContent": true}, fed whole and one character at a time

Related to #1955 (boolean conversion in the completed-call parser only). This PR also covers the streamed arguments, which now go through the same coerce_value as the final call, so the concatenated fragments match it. Rebased onto main after the 0.2.0-beta tracker reset; the change is now a single commit on top of the current coerce_value.

Approach

coerce_value takes the property's schema instead of only its type. After json.loads fails, a new literal_value reads a scalar by the declared type:

  • boolean: true/false in any case; null: null/None; integer: [+-]digits; number: decimal, finite only.
  • With no property schema at all, booleans and None are read too.
  • Kept as text (unchanged from main): any type that includes string; a schema without a top-level type (enum, anyOf, oneOf, const, $ref), so enum: ["None", "Low"] keeps "None"; anything that does not match.
  • Valid JSON keeps its meaning, so "False" (quoted) stays a string. The lenient array/object reading from #4427 is unchanged.
  • A property declared ["string"] is now treated like "string" (verbatim) in both paths; before, {"a":1} in such a field was decoded to an object.

Validation

macOS (Apple silicon), Python 3.12.13, requirements.txt plus jsonschema, revision faab1b4a = main c62d5e3a + this commit. No GPU needed: these are parser and mock-engine tests.

Passed:

  • python -m unittest serve.test_tool_argument_types: 8 tests OK. It checks whole output, character-wise streaming and every two-chunk split, and compares the concatenated tool_args with the final call. The same file against unchanged main gives 28 failures.
  • serve.test_server.UnfinishedToolCall.test_schema_typed_arguments_over_both_apis: OpenAI and Anthropic, streamed and not, through the HTTP server with a mock engine (boolean, integer, nullable, string, enum and anyOf fields).
  • Every other module serve/test_*.py: 1,300 tests, 1 failure, 18 skipped. Unchanged main gives 1,298 tests with the same single failure (test_gpu_roles_server.Roles.test_every_card_off, SystemExit not raised), so this change adds no failure.
  • git diff --check: clean.

Failed:
None caused by this change. The one failure above also happens on unchanged main.

Not run:
No CUDA/HIP/SYCL build: no engine files are touched. No run with a real model or GPU, and no BFCL rerun, so the effect on benchmark scores is not measured.

Limits

  • This is not schema validation: a value that fits neither JSON nor the declared type stays text, as before.
  • For a union that includes string (for example ["string", "null"]), None stays the string "None". The field accepts text, so this PR does not guess.

🤖 Generated with Claude Code


🔄 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/Niko1221/Strata/pull/2371 **Author:** [@anstaendig](https://github.com/anstaendig) **Created:** 10/14/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/tool-argument-schema-coercion` --- ### 📝 Commits (1) - [`faab1b4`](https://github.com/Niko1221/Strata/commit/faab1b4ae211add602c83a1e2e541f73076f9816) serve: read Python-style tool argument literals (True, None, +10) by the declared type, whole and streamed ### 📊 Changes **3 files changed** (+212 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+47 -10) 📝 `serve/test_server.py` (+22 -0) ➕ `serve/test_tool_argument_types.py` (+143 -0) </details> ### 📄 Description ## Problem and result The model sometimes writes tool arguments Python-style, for example `<parameter=onlyMainContent>True</parameter>` or `<parameter=unlock>False</parameter>`. That is not JSON, so `coerce_value` passed the text through and a boolean parameter reached the client as the string `"True"` / `"False"` (truthy either way). Strict tool servers reject it (`expected boolean, received string`, reported above with firecrawl-mcp, and with opencode on 0.2.2 `011c9e6`: 12 of 55 boolean arguments). Reproduced on current `main` (`c62d5e3a`) with `OutputParser(stream_tools=True)` and a tool declaring `onlyMainContent: {"type": "boolean"}`: - before: streamed `tool_args` and the final call both give `{"url": "https://x.y", "onlyMainContent": "True"}` - after: both give `{"url": "https://x.y", "onlyMainContent": true}`, fed whole and one character at a time ## Related discussion Related to #1955 (boolean conversion in the completed-call parser only). This PR also covers the streamed arguments, which now go through the same `coerce_value` as the final call, so the concatenated fragments match it. Rebased onto `main` after the 0.2.0-beta tracker reset; the change is now a single commit on top of the current `coerce_value`. ## Approach `coerce_value` takes the property's schema instead of only its type. After `json.loads` fails, a new `literal_value` reads a scalar by the declared type: - `boolean`: `true`/`false` in any case; `null`: `null`/`None`; `integer`: `[+-]digits`; `number`: decimal, finite only. - With no property schema at all, booleans and `None` are read too. - Kept as text (unchanged from `main`): any type that includes `string`; a schema without a top-level type (`enum`, `anyOf`, `oneOf`, `const`, `$ref`), so `enum: ["None", "Low"]` keeps `"None"`; anything that does not match. - Valid JSON keeps its meaning, so `"False"` (quoted) stays a string. The lenient array/object reading from #4427 is unchanged. - A property declared `["string"]` is now treated like `"string"` (verbatim) in both paths; before, `{"a":1}` in such a field was decoded to an object. ## Validation macOS (Apple silicon), Python 3.12.13, `requirements.txt` plus `jsonschema`, revision `faab1b4a` = `main` `c62d5e3a` + this commit. No GPU needed: these are parser and mock-engine tests. **Passed:** - `python -m unittest serve.test_tool_argument_types`: 8 tests OK. It checks whole output, character-wise streaming and every two-chunk split, and compares the concatenated `tool_args` with the final call. The same file against unchanged `main` gives 28 failures. - `serve.test_server.UnfinishedToolCall.test_schema_typed_arguments_over_both_apis`: OpenAI and Anthropic, streamed and not, through the HTTP server with a mock engine (boolean, integer, nullable, string, `enum` and `anyOf` fields). - Every other module `serve/test_*.py`: 1,300 tests, 1 failure, 18 skipped. Unchanged `main` gives 1,298 tests with the same single failure (`test_gpu_roles_server.Roles.test_every_card_off`, `SystemExit not raised`), so this change adds no failure. - `git diff --check`: clean. **Failed:** None caused by this change. The one failure above also happens on unchanged `main`. **Not run:** No CUDA/HIP/SYCL build: no engine files are touched. No run with a real model or GPU, and no BFCL rerun, so the effect on benchmark scores is not measured. ## Limits - This is not schema validation: a value that fits neither JSON nor the declared type stays text, as before. - For a union that includes `string` (for example `["string", "null"]`), `None` stays the string `"None"`. The field accepts text, so this PR does not guess. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4011
No description provided.