Skip to content

[https://nvbugs/6007352][fix] Accept strict field in tools and store field in chat requests#12482

Merged
JunyiXu-nv merged 1 commit intoNVIDIA:mainfrom
JunyiXu-nv:user/junyix/fix-trtllm-11616
Apr 1, 2026
Merged

[https://nvbugs/6007352][fix] Accept strict field in tools and store field in chat requests#12482
JunyiXu-nv merged 1 commit intoNVIDIA:mainfrom
JunyiXu-nv:user/junyix/fix-trtllm-11616

Conversation

@JunyiXu-nv
Copy link
Copy Markdown
Collaborator

@JunyiXu-nv JunyiXu-nv commented Mar 24, 2026

  • Add strict: Optional[bool] to FunctionDefinition in openai_protocol.py so OpenAI-compatible clients can pass tools[].function.strict without getting an HTTP 400 "extra_forbidden" error.
  • When strict=True, build structural tag guided decoding params to constrain tool call arguments to the function's JSON Schema via the existing structural_tag machinery.
  • Add 14 unit tests covering the new fields and guided decoding logic.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for strict function tools in OpenAI chat completions with automatic structural constraint tagging to ensure tool argument conformance to defined schemas.
  • Tests

    • Added test coverage for strict tool detection, guided decoding construction, and structural tagging behavior across tool parser implementations.

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.

…hat requests

- Add `strict: Optional[bool]` to `FunctionDefinition` in openai_protocol.py
  so OpenAI-compatible clients can pass `tools[].function.strict` without
  getting an HTTP 400 "extra_forbidden" error.
- Add `store: Optional[bool]` to `ChatCompletionRequest` so the `store`
  field is accepted (but not acted on) matching the OpenAI API spec.
- When `strict=True`, build structural tag guided decoding params to
  constrain tool call arguments to the function's JSON Schema via the
  existing `structural_tag` machinery.
- Add 14 unit tests covering the new fields and guided decoding logic.

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
@JunyiXu-nv JunyiXu-nv requested a review from syuoni March 24, 2026 05:41
@JunyiXu-nv JunyiXu-nv requested a review from a team as a code owner March 24, 2026 05:41
@JunyiXu-nv
Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40064 [ run ] triggered by Bot. Commit: 1085480 Link to invocation

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

This PR adds support for strict tool definitions in the OpenAI protocol by introducing an optional strict field to FunctionDefinition, implementing guided decoding logic to enforce structural constraints on strict tools, and adding comprehensive test coverage for the new functionality.

Changes

Cohort / File(s) Summary
OpenAI Protocol Extension
tensorrt_llm/serve/openai_protocol.py
Added optional strict: Optional[bool] = None field to FunctionDefinition class to extend the OpenAI-compatible protocol schema for function tool definitions.
Server-Side Strict Tool Support
tensorrt_llm/serve/openai_server.py
Introduced _build_tool_strict_guided_decoding_params() helper that detects strict tools, validates parser capability for structural tags, and constructs GuidedDecodingParams with appropriate schema constraints. Integrated the helper into openai_chat request handling to automatically apply guided decoding when strict tools are present.
Test Coverage
tests/unittest/llmapi/apps/test_tool_parsers.py
Added extensive unit tests for FunctionDefinition.strict field handling, tool parameter nesting, _build_tool_strict_guided_decoding_params behavior under various conditions (missing/empty/unsupported tools), and structural tag expectations for multiple model variants (Qwen3, DeepSeek).

Sequence Diagram

sequenceDiagram
    participant Client
    participant Server
    participant ToolParser
    participant GuidedDecoding
    participant Generation

    Client->>Server: OpenAI chat request with strict tools
    activate Server
    Server->>Server: Parse request, create sampling_params
    alt Strict tools present and no guided_decoding set
        Server->>ToolParser: Query tool structure info
        activate ToolParser
        ToolParser-->>Server: Return structural constraints
        deactivate ToolParser
        Server->>GuidedDecoding: Build GuidedDecodingParams with structural_tag
        activate GuidedDecoding
        GuidedDecoding-->>Server: Return configured response format
        deactivate GuidedDecoding
        Server->>Server: Set sampling_params.guided_decoding
    end
    Server->>Generation: Execute generation with guided_decoding
    activate Generation
    Generation-->>Server: Generated response
    deactivate Generation
    deactivate Server
    Server-->>Client: OpenAI response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive PR description lists key changes but lacks detail in Description and Test Coverage sections; however, the summary clearly outlines objectives and rationale. Expand Description section with rationale explaining why strict field support improves OpenAI compatibility, and explicitly list the 14 test cases added (or provide test file location) in Test Coverage section.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: adding support for the strict field in tool definitions and integrating it with guided decoding for chat requests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tensorrt_llm/serve/openai_protocol.py (1)

617-621: ⚠️ Potential issue | 🟠 Major

store is still rejected on /v1/chat/completions.

ChatCompletionRequest still inherits extra="forbid" from OpenAIBaseModel, but it does not declare a store field. Clients sending store will therefore keep getting extra_forbidden, so the chat-side compatibility half of this fix is still missing.

Suggested fix
 class ChatCompletionRequest(OpenAIBaseModel):
@@
     tools: Optional[List[ChatCompletionToolsParam]] = None
     tool_choice: Optional[Union[Literal["none", "auto"],
                                 ChatCompletionNamedToolChoiceParam]] = "none"
+    store: Optional[bool] = None
     user: Optional[str] = None

Also applies to: 638-665

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tensorrt_llm/serve/openai_protocol.py` around lines 617 - 621,
ChatCompletionRequest (which inherits extra="forbid" from OpenAIBaseModel) is
missing a store field so clients sending store get extra_forbidden; add a store:
Optional[bool] = None attribute to the ChatCompletionRequest datamodel (and
likewise to any other chat request models in the same region referenced in the
comment, e.g., the chat-request classes between lines ~638-665) so incoming
payloads with "store" are accepted while retaining strict model validation.
🤖 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/openai_server.py`:
- Around line 146-154: The code currently uses "if tool.function.strict and
tool.function.parameters" which treats falsy parameters (None or {}) as
non-strict; change the logic to honor tool.function.strict regardless of
parameters by checking strict first (if tool.function.strict:) and then set
content = {"type": "json_schema", "json_schema": tool.function.parameters or {}}
so an absent or empty parameters object still produces a strict json_schema;
otherwise (if not strict) fall back to {"type": "any_text"}.

---

Outside diff comments:
In `@tensorrt_llm/serve/openai_protocol.py`:
- Around line 617-621: ChatCompletionRequest (which inherits extra="forbid" from
OpenAIBaseModel) is missing a store field so clients sending store get
extra_forbidden; add a store: Optional[bool] = None attribute to the
ChatCompletionRequest datamodel (and likewise to any other chat request models
in the same region referenced in the comment, e.g., the chat-request classes
between lines ~638-665) so incoming payloads with "store" are accepted while
retaining strict model validation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f0cf88db-1b68-47fd-94ee-c14d9681d380

📥 Commits

Reviewing files that changed from the base of the PR and between 14a75ee and 1085480.

📒 Files selected for processing (3)
  • tensorrt_llm/serve/openai_protocol.py
  • tensorrt_llm/serve/openai_server.py
  • tests/unittest/llmapi/apps/test_tool_parsers.py

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40064 [ run ] completed with state SUCCESS. Commit: 1085480
/LLM/main/L0_MergeRequest_PR pipeline #31218 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@JunyiXu-nv
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40218 [ run ] triggered by Bot. Commit: 1085480 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40218 [ run ] completed with state SUCCESS. Commit: 1085480
/LLM/main/L0_MergeRequest_PR pipeline #31355 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@JunyiXu-nv
Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40406 [ run ] triggered by Bot. Commit: 1085480 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40406 [ run ] completed with state FAILURE. Commit: 1085480
/LLM/main/L0_MergeRequest_PR pipeline #31501 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@JunyiXu-nv
Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40569 [ run ] triggered by Bot. Commit: 1085480 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40569 [ run ] completed with state DISABLED
CI server is currently disabled for scheduled maintenance. Estimated completion time: 11 PM PST on 3/28.

Link to invocation

@JunyiXu-nv
Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40910 [ run ] triggered by Bot. Commit: 1085480 Link to invocation

@JunyiXu-nv
Copy link
Copy Markdown
Collaborator Author

/bot run

@JunyiXu-nv JunyiXu-nv enabled auto-merge (squash) April 1, 2026 03:15
@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #41095 [ run ] triggered by Bot. Commit: 1085480 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #41095 [ run ] completed with state FAILURE. Commit: 1085480
/LLM/main/L0_MergeRequest_PR pipeline #32069 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@JunyiXu-nv
Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #41123 [ run ] triggered by Bot. Commit: 1085480 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #41123 [ run ] completed with state FAILURE. Commit: 1085480
/LLM/main/L0_MergeRequest_PR pipeline #32095 completed with status: 'ABORTED'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@JunyiXu-nv
Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #41139 [ run ] triggered by Bot. Commit: 1085480 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #41139 [ run ] completed with state SUCCESS. Commit: 1085480
/LLM/main/L0_MergeRequest_PR pipeline #32110 completed with status: 'SUCCESS'

CI Report

Link to invocation

@JunyiXu-nv JunyiXu-nv merged commit 5c00204 into NVIDIA:main Apr 1, 2026
9 of 10 checks passed
karen-sy pushed a commit to karen-sy/TensorRT-LLM that referenced this pull request Apr 7, 2026
…field in chat requests (NVIDIA#12482)

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants