Skip to content

[https://nvbugs/6284101][fix] Fix guided decoding for Harmony parser - #15741

Open
dongfengy wants to merge 11 commits into
NVIDIA:mainfrom
dongfengy:codex/6284101-guided-decoding-harmony
Open

[https://nvbugs/6284101][fix] Fix guided decoding for Harmony parser#15741
dongfengy wants to merge 11 commits into
NVIDIA:mainfrom
dongfengy:codex/6284101-guided-decoding-harmony

Conversation

@dongfengy

@dongfengy dongfengy commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • Adds model-aware guided-decoding adaptation for GPT-OSS Harmony output in the raw Python LLM.generate() path.
  • Applies JSON, regex, and grammar constraints after the Harmony final-channel marker.
  • Reuses the adaptation logic in the serving path.
  • Adds final-content extraction for Harmony and other reasoning parsers.
  • Updates JSON-mode evaluation to score parser-selected final content.
  • Preserves existing behavior for normal reasoning parsers, llguidance, plain models, and unsupported guides.
  • Adds fallback handling when reasoning parsing fails or returns no content.
  • No configuration or public API changes require review.
  • No test-list files were modified.

QA Engineer Review

  • Added coverage for extract_final_content_from_generation, including raw output, explicit qwen3, non-Harmony parsers, token IDs, and explicit Harmony parsing.
  • Added coverage for Harmony guided-decoding adaptation, JSON schemas, schema properties, parser resolution, unsupported guides, plain models, and normal reasoning-parser sequences.
  • No modified or removed test functions were reported.
  • No test-list coverage entries were added or changed.
  • Verdict: needs follow-up because test-list coverage data is unavailable.

Description

Fix guided decoding for the raw Python LLM.generate() path when GPT-OSS uses the Harmony protocol with xgrammar. Caller-provided JSON, regex, and grammar constraints are enriched with model-aware Harmony framing so they apply only after the final-channel marker instead of constraining the reasoning transcript.

The serving path keeps its existing behavior while sharing the same reasoning-parser adapter. JSON-mode evaluation now scores parser-selected final content, covering plain output, explicit Harmony output, and explicit normal reasoning-parser output without guessing a parser for unrelated models.

Raw guided-decoding behavior remains unchanged for normal reasoning parsers and llguidance. This PR does not change the public API.

Test Coverage

  • Post-rebase pre-commit on all changed files: passed on exact head 059d1c9a76.
  • Incremental CUDA 13.2/TensorRT 10.16 SM90+SM100 rebuild on exact head 059d1c9a76: passed.
  • Focused guide-adaptation/final-content units: 46 passed; strict tool-guided construction: 8 passed.
  • Broad affected unit/API/bindings suite: 185 passed, with the same three unrelated upstream Qwen3 auto-detection failures from missing logger methods.
  • Qwen3 raw sync+async: passed with xgrammar and llguidance; Qwen3 100-sample JSON evaluation: 77/100.
  • Llama-3.1-8B guided decoding: xgrammar and llguidance both passed (2 passed, 74/100 each).
  • Exact four-B200 GPT-OSS/Eagle3 regression on 059d1c9a76: passed with JSON accuracy 78/100 and grammar accuracy 96/100 (threshold 50.369).

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)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • 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.

@dongfengy
dongfengy force-pushed the codex/6284101-guided-decoding-harmony branch from 558e70c to ab42d37 Compare June 30, 2026 00:09
@dongfengy
dongfengy marked this pull request as ready for review June 30, 2026 00:15
@dongfengy
dongfengy requested a review from a team as a code owner June 30, 2026 00:15
@dongfengy
dongfengy requested a review from zhenhuaw-me June 30, 2026 00:15
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: abc26cf5-dff0-47bd-b05f-5f222f952a85

📥 Commits

Reviewing files that changed from the base of the PR and between 306dd6e and 43ce9fa.

📒 Files selected for processing (1)
  • tensorrt_llm/evaluate/json_mode_eval.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tensorrt_llm/evaluate/json_mode_eval.py

Walkthrough

Adds reasoning-parser-aware guided-decoding adaptation for Harmony and other reasoning formats. Wires the shared adaptation into LLM sampling and OpenAI serving. Adds final-content extraction and reasoning-aware JSON evaluation.

Changes

Reasoning-parser guided decoding and evaluation

Layer / File(s) Summary
Parser resolution and guided-decoding adaptation
tensorrt_llm/llmapi/reasoning_parser.py
Adds Harmony constants, parser resolution, guide conversion, and final-content constraints for supported guided-decoding formats.
Runtime guided-decoding wiring
tensorrt_llm/llmapi/llm.py, tensorrt_llm/serve/openai_protocol.py
Applies parser-specific guided-decoding adaptation during sampling preparation and replaces duplicated OpenAI protocol logic with the shared helper.
Reasoning-aware content extraction and JSON evaluation
tensorrt_llm/evaluate/interface.py, tensorrt_llm/evaluate/json_mode_eval.py
Extracts final content from generated output and uses configured reasoning parsers during JSON-mode evaluation.
Parser adaptation and extraction tests
tests/unittest/evaluate/test_generation_content.py, tests/unittest/llmapi/test_sampling_params.py
Tests parser resolution, Harmony constraints, schema handling, unchanged guides, and final-content extraction.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant LLM
  participant ReasoningParser
  participant JsonModeEval
  Client->>LLM: Submit guided-decoding parameters
  LLM->>ReasoningParser: Resolve and adapt parser framing
  ReasoningParser-->>LLM: Return adapted guided-decoding parameters
  LLM-->>JsonModeEval: Return generated output
  JsonModeEval->>ReasoningParser: Extract final content
  ReasoningParser-->>JsonModeEval: Return parsed content
Loading

Possibly related PRs

Suggested labels: ci: full pre-merge approved

Suggested reviewers: mikeiovine

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required ticket and type format and clearly states the main guided-decoding fix for Harmony.
Description check ✅ Passed The description explains the problem and solution, lists relevant test coverage, and includes the required checklist with the review confirmation checked.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/evaluate/interface.py`:
- Around line 90-109: The fallback parsing in interface.py is catching all
Exception in both the harmony adapter path and the ReasoningParserFactory path,
which can mask real bugs. Update the try/except blocks around
get_harmony_adapter().harmony_output_to_openai and parser.parse(text) to catch
only the expected import, parsing, or type-related failures, and leave
unexpected exceptions to surface. Keep the same fallback-to-text behavior, but
narrow the exception handling in these parser paths to the smallest specific set
possible.

In `@tensorrt_llm/evaluate/json_mode_eval.py`:
- Around line 33-48: Add a return type annotation to _load_json_from_generation
in json_mode_eval.py, and if helpful introduce a local alias for the JSON value
type to keep the signature readable. Update the function signature of
_load_json_from_generation (and any related helper typing if needed) so the new
helper is fully annotated per the codebase guidelines.

In `@tests/unittest/evaluate/test_generation_content.py`:
- Around line 1-2: The new test file currently has only an SPDX-only header, but
it needs the repository’s full NVIDIA copyright/license header block. Update the
top-of-file header in test_generation_content.py to match the required NVIDIA
format used elsewhere in the repo, including the year of the latest meaningful
modification and the standard Apache-2.0 license notice.
- Around line 23-42: Add a test in test_generation_content for
extract_final_content_from_generation that combines token_ids with
reasoning_parser="qwen3" and asserts the qwen3 path still wins. Mirror the
existing test_extract_final_content_does_not_guess_harmony_from_tokens setup by
monkeypatching tensorrt_llm.serve.harmony_adapter.get_harmony_adapter to raise
if called, then verify the function returns the expected final content. This
should cover the explicit non-Harmony parser branch even when token_ids are
present and prevent future regressions in extract_final_content_from_generation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 318d2a29-586e-453d-ab59-726c7b606634

📥 Commits

Reviewing files that changed from the base of the PR and between e901627 and ab42d37.

📒 Files selected for processing (7)
  • tensorrt_llm/evaluate/interface.py
  • tensorrt_llm/evaluate/json_mode_eval.py
  • tensorrt_llm/llmapi/llm.py
  • tensorrt_llm/llmapi/reasoning_parser.py
  • tensorrt_llm/serve/openai_protocol.py
  • tests/unittest/evaluate/test_generation_content.py
  • tests/unittest/llmapi/test_sampling_params.py

Comment thread tensorrt_llm/evaluate/interface.py
Comment thread tensorrt_llm/evaluate/json_mode_eval.py Outdated
Comment thread tests/unittest/evaluate/test_generation_content.py
Comment thread tests/unittest/evaluate/test_generation_content.py
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@dongfengy
dongfengy force-pushed the codex/6284101-guided-decoding-harmony branch from ab42d37 to 059d1c9 Compare June 30, 2026 03:00
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

1 similar comment
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56512 [ run ] triggered by Bot. Commit: 059d1c9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56512 [ run ] completed with state SUCCESS. Commit: 059d1c9
/LLM/main/L0_MergeRequest_PR pipeline #45351 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

CI Agent Failure Analysis

Link to invocation

@dongfengy dongfengy changed the title [https://nvbugs/6284101][fix] fix guided decoding for harmony parser [TRTLLM-13773,https://nvbugs/6284101][fix] fix guided decoding for harmony parser Jun 30, 2026
@dongfengy
dongfengy force-pushed the codex/6284101-guided-decoding-harmony branch 2 times, most recently from 0b38f28 to baf824c Compare June 30, 2026 17:31
@dongfengy dongfengy changed the title [TRTLLM-13773,https://nvbugs/6284101][fix] fix guided decoding for harmony parser [https://nvbugs/6284101][fix] Fix guided decoding for Harmony parser Jun 30, 2026
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56678 [ run ] triggered by Bot. Commit: baf824c Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56678 [ run ] completed with state ABORTED. Commit: baf824c
/LLM/main/L0_MergeRequest_PR pipeline #45501 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

CI Agent Failure Analysis

Link to invocation

@dongfengy
dongfengy force-pushed the codex/6284101-guided-decoding-harmony branch from baf824c to 0dac1c9 Compare June 30, 2026 23:49
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56761 [ run ] triggered by Bot. Commit: 0dac1c9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56761 [ run ] completed with state SUCCESS. Commit: 0dac1c9
/LLM/main/L0_MergeRequest_PR pipeline #45580 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

CI Agent Failure Analysis

Link to invocation

@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56850 [ run ] triggered by Bot. Commit: 0dac1c9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56850 [ run ] completed with state SUCCESS. Commit: 0dac1c9
/LLM/main/L0_MergeRequest_PR pipeline #45661 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

CI Agent Failure Analysis

Link to invocation

@dongfengy
dongfengy force-pushed the codex/6284101-guided-decoding-harmony branch from 0dac1c9 to 0cbb805 Compare July 6, 2026 23:43
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57856 [ run ] triggered by Bot. Commit: 0cbb805 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57856 [ run ] completed with state FAILURE. Commit: 0cbb805
/LLM/main/L0_MergeRequest_PR pipeline #46552 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

CI Agent Failure Analysis

Link to invocation

@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57981 [ run ] triggered by Bot. Commit: 0cbb805 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57981 [ run ] completed with state SUCCESS. Commit: 0cbb805
/LLM/main/L0_MergeRequest_PR pipeline #46653 completed with status: 'SUCCESS'

CI Report

Link to invocation

Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
@dongfengy
dongfengy force-pushed the codex/6284101-guided-decoding-harmony branch from 0cbb805 to 306dd6e Compare August 9, 2026 05:55
@dongfengy
dongfengy requested review from a team as code owners August 9, 2026 05:55
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/unittest/llmapi/test_sampling_params.py (1)

216-371: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add Harmony conversion tests for json_object, regex, and grammar. _guided_decoding_content converts all three types, but the tests only assert Harmony conversion for json.

Coverage summary: Added tests cover nine functions: test_harmony_guided_decoding_triggers_on_final_channel, test_harmony_guided_decoding_accepts_json_schema_string, test_guided_decoding_preserves_top_level_schema_property, test_resolve_guided_decoding_reasoning_parser, test_resolve_raw_guided_decoding_reasoning_parser, test_raw_llm_preserves_guides_outside_harmony_xgrammar, test_plain_model_guided_decoding_is_unchanged, test_reasoning_parser_guided_decoding_uses_sequence_for_normal_parser, and test_existing_structural_tag_guided_decoding_is_unchanged. The target file is listed in tests/integration/test_lists/test-db/l0_cpu.yml. Coverage verdict: insufficient.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unittest/llmapi/test_sampling_params.py` around lines 216 - 371, Add
Harmony conversion tests for GuidedDecodingParams json_object, regex, and
grammar inputs, exercising adapt_guided_decoding_params_for_reasoning_parser and
asserting each produces the expected structural-tag content. Keep the existing
JSON tests and surrounding parser-resolution coverage unchanged.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/evaluate/json_mode_eval.py`:
- Around line 31-36: Update the imports in json_mode_eval.py to define the
annotation symbols used by JsonValue and the LLM-related code: import Union from
typing and import LLM from the existing LLM API module used by the file. Keep
the annotations and surrounding logic unchanged.

In `@tensorrt_llm/llmapi/reasoning_parser.py`:
- Around line 177-188: Define recursive JsonValue and structural-tag TypedDict
aliases, then update _normalize_json_schema_for_structural_tag to accept str |
BaseModel | dict[str, JsonValue] and return JsonValue. Change
_guided_decoding_content to return the structural-tag content TypedDict or None,
replacing Any and bare dict types without altering behavior.

---

Nitpick comments:
In `@tests/unittest/llmapi/test_sampling_params.py`:
- Around line 216-371: Add Harmony conversion tests for GuidedDecodingParams
json_object, regex, and grammar inputs, exercising
adapt_guided_decoding_params_for_reasoning_parser and asserting each produces
the expected structural-tag content. Keep the existing JSON tests and
surrounding parser-resolution coverage unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: be1fe29b-b3ed-4461-9a58-40eb955645af

📥 Commits

Reviewing files that changed from the base of the PR and between 1d7c771 and 306dd6e.

📒 Files selected for processing (7)
  • tensorrt_llm/evaluate/interface.py
  • tensorrt_llm/evaluate/json_mode_eval.py
  • tensorrt_llm/llmapi/llm.py
  • tensorrt_llm/llmapi/reasoning_parser.py
  • tensorrt_llm/serve/openai_protocol.py
  • tests/unittest/evaluate/test_generation_content.py
  • tests/unittest/llmapi/test_sampling_params.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • tests/unittest/evaluate/test_generation_content.py
  • tensorrt_llm/evaluate/interface.py
  • tensorrt_llm/llmapi/llm.py
  • tensorrt_llm/serve/openai_protocol.py

Comment thread tensorrt_llm/evaluate/json_mode_eval.py
Comment on lines +177 to +188
def _normalize_json_schema_for_structural_tag(json_schema: Any) -> Any:
"""Convert supported schema representations to structural-tag JSON."""
if hasattr(json_schema, "model_json_schema"):
json_schema = json_schema.model_json_schema()
if isinstance(json_schema, str):
json_schema = json.loads(json_schema)
return json_schema


def _guided_decoding_content(
guided_decoding_params: GuidedDecodingParams) -> Optional[dict]:
"""Translate an ordinary guide into structural-tag content."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

ast-grep outline tensorrt_llm/llmapi/reasoning_parser.py --items all --type function
rg -n -C 2 --glob '*.py' \
  'GuidedDecodingParams\(|_normalize_json_schema_for_structural_tag' \
  tensorrt_llm tests

Repository: NVIDIA/TensorRT-LLM

Length of output: 21804


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- candidate files ---'
fd -i 'CODING_GUIDELINES.md|sampling_params.py|reasoning_parser.py' .

printf '%s\n' '--- GuidedDecodingParams declaration and imports ---'
rg -n -C 8 \
  'class GuidedDecodingParams|json:|from pydantic|from typing|TypeAlias|JsonValue|JSON' \
  tensorrt_llm/sampling_params.py tensorrt_llm/llmapi/reasoning_parser.py

printf '%s\n' '--- relevant implementation ---'
sed -n '1,35p;130,270p' tensorrt_llm/llmapi/reasoning_parser.py
sed -n '620,790p' tensorrt_llm/sampling_params.py

printf '%s\n' '--- relevant tests ---'
sed -n '190,285p;300,375p' tests/unittest/llmapi/test_sampling_params.py

printf '%s\n' '--- typing conventions ---'
rg -n -C 2 \
  'JsonValue|JSONValue|TypeAlias|dict\[str, .*\]|BaseModel.*model_json_schema|model_json_schema' \
  tensorrt_llm tests --glob '*.py' | head -n 240

printf '%s\n' '--- coding guidelines ---'
if [ -f CODING_GUIDELINES.md ]; then
  sed -n '1,240p' CODING_GUIDELINES.md
else
  printf '%s\n' 'CODING_GUIDELINES.md not found at repository root'
fi

Repository: NVIDIA/TensorRT-LLM

Length of output: 50377


🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n -C 12 'class GuidedDecodingParams|json:' tensorrt_llm/sampling_params.py
sed -n '170,220p' tensorrt_llm/llmapi/reasoning_parser.py
sed -n '200,280p' tests/unittest/llmapi/test_sampling_params.py
rg -n -C 2 'JsonValue|JSONValue|TypeAlias|model_json_schema' tensorrt_llm tests --glob '*.py' | head -n 200

Repository: NVIDIA/TensorRT-LLM

Length of output: 20848


🏁 Script executed:

#!/bin/bash
set -euo pipefail
printf '%s\n' '--- declaration ---'
rg -n -C 15 'class GuidedDecodingParams|json:.*Optional|json:.*Union' tensorrt_llm/sampling_params.py
printf '%s\n' '--- helper implementation ---'
sed -n '165,225p' tensorrt_llm/llmapi/reasoning_parser.py
printf '%s\n' '--- tests ---'
sed -n '205,285p' tests/unittest/llmapi/test_sampling_params.py
printf '%s\n' '--- related aliases and schema typing ---'
rg -n -C 3 'JsonValue|JSONValue|TypeAlias|model_json_schema|BaseModel' tensorrt_llm tests --glob '*.py' | head -n 240

Repository: NVIDIA/TensorRT-LLM

Length of output: 23122


🌐 Web query:

NVIDIA TensorRT-LLM sampling_params.py GuidedDecodingParams json Type BaseModel

💡 Result:

In NVIDIA TensorRT-LLM, the GuidedDecodingParams class is defined in tensorrt_llm/sampling_params.py to configure constraints for text generation [1][2]. The json field within this class accepts a value of type Union[str, BaseModel, dict] [1][3]. When providing a Pydantic BaseModel to the json parameter, TensorRT-LLM automatically handles the schema conversion, as the implementation internally checks for the BaseModel type and calls its model_json_schema method to extract the necessary schema for guided decoding [4]. This functionality allows developers to define complex generation constraints using familiar Pydantic models, which are then passed via SamplingParams to the model's generation methods [5][6]. Summary of GuidedDecodingParams.json type: Type: Optional[Union[str, BaseModel, dict]] [1][3] Purpose: Allows the user to specify a JSON schema (as a string, dictionary, or Pydantic model) to restrict the model's output format [1][5]. Usage: If a Pydantic BaseModel is provided, the library converts it to a JSON schema automatically before processing [4]. Note: Only one guide type (e.g., json, regex, grammar) can be effectively used in a single GuidedDecodingParams instance; the class includes a _validate method to enforce this constraint [1][2].

Citations:


Use precise types for the structural-tag helpers.

Define recursive JsonValue and structural-tag TypedDict aliases. Type schema inputs as str | BaseModel | dict[str, JsonValue], normalized schemas as JsonValue, and _guided_decoding_content as the structural-tag content type or None. Do not use Any or bare dict.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/llmapi/reasoning_parser.py` around lines 177 - 188, Define
recursive JsonValue and structural-tag TypedDict aliases, then update
_normalize_json_schema_for_structural_tag to accept str | BaseModel | dict[str,
JsonValue] and return JsonValue. Change _guided_decoding_content to return the
structural-tag content TypedDict or None, replacing Any and bare dict types
without altering behavior.

Sources: Coding guidelines, Learnings

Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64838 [ run ] triggered by Bot. Commit: 43ce9fa Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64838 [ run ] completed with state SUCCESS. Commit: 43ce9fa
/LLM/main/L0_MergeRequest_PR pipeline #52679 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

CI Agent Failure Analysis

Link to invocation

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.

2 participants