[https://nvbugs/5944411][fix] Handle anyOf parameter schemas in Qwen3Coder tool parser#12173
Conversation
Parameters using anyOf (e.g. Optional[int]) have no top-level "type" key, causing _convert_param_value to always default to "string". Treat anyOf schemas as "object" to trigger json.loads, which correctly parses integers, floats, booleans, objects, and arrays. Signed-off-by: Joyjit Daw <1127155+tijyojwad@users.noreply.github.com> Made-with: Cursor
📝 WalkthroughWalkthroughAdds support for OpenAPI-style anyOf parameter schemas in the Qwen3 coder parser by treating anyOf entries as object types instead of defaulting to strings. When parameter config contains "anyOf", the parser now sets the parameter type to "object" to enable proper JSON parsing. Includes comprehensive unit tests validating type coercion and null value handling across multiple anyOf-based parameter types. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment Tip You can disable sequence diagrams in the walkthrough.Disable the |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/unittest/llmapi/apps/test_tool_parsers.py (1)
1010-1130: Add one literal-like string case foranyOf: [string, null]Great coverage overall. Consider adding a case where
labelistrue(unquoted) and assert it remains"true"as a string. That will guard against unintended coercion in union-with-null string schemas.✅ Suggested test addition
def test_parse_anyof_parameter_type_conversion(self, parser): @@ assert params["tags"] == [1, 2, 3] assert params["label"] == "hello" + + text_string_literal = ("<tool_call>\n" + "<function=create_record>\n" + "<parameter=name>test</parameter>\n" + "<parameter=label>true</parameter>\n" + "</function>\n" + "</tool_call>") + result_string_literal = parser.detect_and_parse(text_string_literal, [tool_def]) + params_string_literal = json.loads(result_string_literal.calls[0].parameters) + assert params_string_literal["label"] == "true"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unittest/llmapi/apps/test_tool_parsers.py` around lines 1010 - 1130, Update the anyOf string/null coverage by adding a literal-like case for the "label" field in test_parse_anyof_parameter_type_conversion (or as a new test) where the input uses an unquoted true token (<parameter=label>true</parameter>); run parser.detect_and_parse and assert that result.calls[0].parameters parses "label" to the string "true" (and isinstance(params["label"], str)) to ensure no coercion to boolean occurs for anyOf: [{type: "string"}, {type: "null"}].
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tensorrt_llm/serve/tool_parser/qwen3_coder_parser.py`:
- Around line 377-379: The code currently forces param_type = "object" whenever
param_config[param_name] has "anyOf"; instead, inspect
param_config[param_name]["anyOf"] to find concrete non-null subtype(s) and set
param_type to that subtype when unambiguous (e.g., pick "string" if anyOf
contains {"type":"string"} and {"type":"null"}), otherwise fall back to
"object"; update the logic around param_config[param_name] and param_type so
values like true/false are parsed as boolean when anyOf includes boolean, and
ensure null remains allowed when anyOf includes null.
---
Nitpick comments:
In `@tests/unittest/llmapi/apps/test_tool_parsers.py`:
- Around line 1010-1130: Update the anyOf string/null coverage by adding a
literal-like case for the "label" field in
test_parse_anyof_parameter_type_conversion (or as a new test) where the input
uses an unquoted true token (<parameter=label>true</parameter>); run
parser.detect_and_parse and assert that result.calls[0].parameters parses
"label" to the string "true" (and isinstance(params["label"], str)) to ensure no
coercion to boolean occurs for anyOf: [{type: "string"}, {type: "null"}].
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a9a72c29-b24c-40c1-afad-bb3d1a0701b6
📒 Files selected for processing (2)
tensorrt_llm/serve/tool_parser/qwen3_coder_parser.pytests/unittest/llmapi/apps/test_tool_parsers.py
|
/bot run |
|
PR_Github #38792 [ run ] triggered by Bot. Commit: |
|
PR_Github #38792 [ run ] completed with state
|
|
/bot run --only-multi-gpu-test --disable-fail-fast |
|
PR_Github #38883 [ run ] triggered by Bot. Commit: |
|
PR_Github #38883 [ run ] completed with state |
51cd1ad to
a9353bc
Compare
|
/bot help |
GitHub Bot Help
Provide a user friendly way for developers to interact with a Jenkins server. Run See details below for each supported subcommand. Details
Launch build/test pipelines. All previously running jobs will be killed.
kill
Kill all running builds associated with pull request. skip
Skip testing for latest commit on pull request. reuse-pipeline
Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break. |
|
/bot --reuse-test 30191 |
GitHub Bot Help
Provide a user friendly way for developers to interact with a Jenkins server. Run See details below for each supported subcommand. Details
Launch build/test pipelines. All previously running jobs will be killed.
kill
Kill all running builds associated with pull request. skip
Skip testing for latest commit on pull request. reuse-pipeline
Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break. |
|
/bot run --reuse-test 30191 |
|
PR_Github #38897 [ run ] triggered by Bot. Commit: |
|
/bot help |
GitHub Bot Help
Provide a user friendly way for developers to interact with a Jenkins server. Run See details below for each supported subcommand. Details
Launch build/test pipelines. All previously running jobs will be killed.
kill
Kill all running builds associated with pull request. skip
Skip testing for latest commit on pull request. reuse-pipeline
Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break. |
|
PR_Github #38897 [ run ] completed with state
|
|
/bot reuse-pipeline --number 12173 |
|
PR_Github #38911 [ reuse-pipeline ] triggered by Bot. Commit: |
|
PR_Github #38911 [ reuse-pipeline ] completed with state |
|
/bot skip --comment "CI passed with same code change." |
|
PR_Github #38917 [ skip ] triggered by Bot. Commit: |
|
PR_Github #38917 [ skip ] completed with state |

Parameters using anyOf (e.g. Optional[int]) have no top-level "type" key, causing _convert_param_value to always default to "string". Treat anyOf schemas as "object" to trigger json.loads, which correctly parses integers, floats, booleans, objects, and arrays.
Made-with: Cursor
Fix cherry picked from vllm-project/vllm#36032
Summary by CodeRabbit
Release Notes
New Features
Tests
Description
Test Coverage
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.