Skip to content

[https://nvbugs/6384951][fix] Fix incorrect error reporting#15732

Open
2ez4bz wants to merge 1 commit into
NVIDIA:mainfrom
2ez4bz:dev-nvbug-6384951
Open

[https://nvbugs/6384951][fix] Fix incorrect error reporting#15732
2ez4bz wants to merge 1 commit into
NVIDIA:mainfrom
2ez4bz:dev-nvbug-6384951

Conversation

@2ez4bz

@2ez4bz 2ez4bz commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Improved chat tool-call parsing to handle raw or partially formed inputs more reliably.
    • Added clearer error messages when tool-call data is missing, malformed, or contains invalid JSON.
    • Preserved extra fields and optional values during fallback parsing while still normalizing valid arguments.

Description

  • Why?

tau2-bench required a workaround that could misreport errors.

  • What?

This commit fixes that with typed checks and adds tests for it.

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)

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

@2ez4bz 2ez4bz requested a review from a team as a code owner June 29, 2026 20:21
@2ez4bz 2ez4bz requested a review from zhenhuaw-me June 29, 2026 20:21
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds Pydantic-based fallback validation for raw tool-call lists in _parse_assistant_message_content. New internal models and a TypeAdapter re-validate unvalidated dicts, format validation errors into client-facing ValueErrors, and guard JSON decoding of function.arguments. Tests cover missing function, invalid JSON arguments, non-object shapes, and lenient extra-field preservation.

Tool-Call Fallback Validation

Layer / File(s) Summary
Fallback Pydantic models and validator helpers
tensorrt_llm/serve/chat_utils.py
Adds Pydantic imports; defines _FallbackFunctionCall, _FallbackToolCall models with extra="allow", a TypeAdapter, _format_tool_call_error, and _validate_fallback_tool_calls that converts ValidationError to ValueError.
Integration and normalization updates
tensorrt_llm/serve/chat_utils.py, tests/unittest/llmapi/apps/test_chat_utils.py
Updates _parse_assistant_message_content to branch on list vs iterator, calls the new validator, unconditionally casts function to dict, and wraps json.JSONDecodeError. Tests assert specific ValueError messages for missing/invalid function, invalid JSON arguments, and verify lenient extra-field preservation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% 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
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.
Title check ✅ Passed The title matches the change and includes the NVBugs ID and fix type.
Description check ✅ Passed The description covers why, what, and the checklist, though the Test Coverage section is not filled in.
✨ 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: 2

🧹 Nitpick comments (2)
tests/unittest/llmapi/apps/test_chat_utils.py (1)

120-213: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add -> None to the new test methods.

These newly added test functions omit return annotations. As per coding guidelines, “Always annotate functions with return types (use None if no return).”

🤖 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/apps/test_chat_utils.py` around lines 120 - 213, The
new test methods in test_chat_utils.py are missing explicit return annotations.
Update each added test function, including
test_assistant_message_tool_call_missing_function,
test_assistant_message_tool_call_invalid_json_arguments,
test_assistant_message_tool_call_non_object_function,
test_assistant_message_tool_call_non_object_item, and
test_assistant_message_tool_call_preserves_extra_fields, to declare a None
return type so they comply with the function annotation guideline.

Source: Coding guidelines

tensorrt_llm/serve/chat_utils.py (1)

280-316: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use Python 3.10 built-in generics here. Replace Optional[...], Union[...], List[...], and Dict[...] with | and list/dict in the new fallback helpers to match the repo’s Python 3.10 target and keep the annotations consistent.

Proposed annotation cleanup
-    name: Optional[str] = None
-    arguments: Optional[Union[str, Dict[str, Any]]] = None
+    name: str | None = None
+    arguments: str | dict[str, Any] | None = None
@@
-_FALLBACK_TOOL_CALLS_ADAPTER = TypeAdapter(List[_FallbackToolCall])
+_FALLBACK_TOOL_CALLS_ADAPTER = TypeAdapter(list[_FallbackToolCall])
@@
-def _format_tool_call_error(errors: List[Dict[str, Any]]) -> str:
+def _format_tool_call_error(errors: list[dict[str, Any]]) -> str:
@@
-def _validate_fallback_tool_calls(
-        tool_calls: List[Any]) -> List[Dict[str, Any]]:
+def _validate_fallback_tool_calls(
+        tool_calls: list[Any]) -> list[dict[str, Any]]:
🤖 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/serve/chat_utils.py` around lines 280 - 316, Update the new
fallback helper annotations in chat_utils.py to use Python 3.10 built-in
generics and unions instead of Optional, Union, List, and Dict. Adjust the type
hints on _FallbackFunctionCall, _FallbackToolCall, _FALLBACK_TOOL_CALLS_ADAPTER,
_format_tool_call_error, and _validate_fallback_tool_calls to use list, dict,
and | consistently with the repo’s Python 3.10 target.

Sources: Coding guidelines, Learnings

🤖 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/serve/chat_utils.py`:
- Around line 361-368: The argument parsing in chat_utils.py is incorrectly
gated on truthiness, so empty strings skip JSON decoding and non-dict JSON like
"[]" or "0" can be accepted. Update the function handling tool call arguments so
it distinguishes None from string values in item["function"]["arguments"],
always attempts json.loads for string inputs, and then validates the parsed
result is a dict/object before assigning it back. Keep the existing ValueError
path in the same argument-normalization flow so invalid JSON and non-object
payloads are both rejected consistently.

In `@tests/unittest/llmapi/apps/test_chat_utils.py`:
- Around line 130-150: Expand parse_chat_message_content coverage in
test_chat_utils by adding cases for empty string arguments and valid non-object
JSON values like [] or 0 in
test_assistant_message_tool_call_invalid_json_arguments or nearby tests. The
current invalid-JSON assertion only covers malformed syntax; update the tests to
verify the tool_calls[0].function.arguments normalization path rejects empty and
non-object JSON too, with ValueError matches that make the failure reason
explicit.

---

Nitpick comments:
In `@tensorrt_llm/serve/chat_utils.py`:
- Around line 280-316: Update the new fallback helper annotations in
chat_utils.py to use Python 3.10 built-in generics and unions instead of
Optional, Union, List, and Dict. Adjust the type hints on _FallbackFunctionCall,
_FallbackToolCall, _FALLBACK_TOOL_CALLS_ADAPTER, _format_tool_call_error, and
_validate_fallback_tool_calls to use list, dict, and | consistently with the
repo’s Python 3.10 target.

In `@tests/unittest/llmapi/apps/test_chat_utils.py`:
- Around line 120-213: The new test methods in test_chat_utils.py are missing
explicit return annotations. Update each added test function, including
test_assistant_message_tool_call_missing_function,
test_assistant_message_tool_call_invalid_json_arguments,
test_assistant_message_tool_call_non_object_function,
test_assistant_message_tool_call_non_object_item, and
test_assistant_message_tool_call_preserves_extra_fields, to declare a None
return type so they comply with the function annotation guideline.
🪄 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: 9aacfde3-16a1-4684-a87c-3e5e9d7de868

📥 Commits

Reviewing files that changed from the base of the PR and between 863bc4e and 51ccb9e.

📒 Files selected for processing (2)
  • tensorrt_llm/serve/chat_utils.py
  • tests/unittest/llmapi/apps/test_chat_utils.py

Comment thread tensorrt_llm/serve/chat_utils.py Outdated
Comment thread tests/unittest/llmapi/apps/test_chat_utils.py Outdated
@2ez4bz 2ez4bz changed the title [https://nvbugs/6384951] Fix incorrect error reporting [https://nvbugs/6384951][fix] Fix incorrect error reporting Jun 29, 2026
@2ez4bz 2ez4bz force-pushed the dev-nvbug-6384951 branch from 51ccb9e to b2efdab Compare June 29, 2026 21:27
@2ez4bz

2ez4bz commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56466 [ run ] triggered by Bot. Commit: b2efdab Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56466 [ run ] completed with state FAILURE. Commit: b2efdab
/LLM/main/L0_MergeRequest_PR pipeline #45306 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

@2ez4bz 2ez4bz force-pushed the dev-nvbug-6384951 branch from b2efdab to 25dc000 Compare June 30, 2026 21:20
@2ez4bz

2ez4bz commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56729 [ run ] triggered by Bot. Commit: 25dc000 Link to invocation

@juney-nvidia juney-nvidia requested a review from JunyiXu-nv June 30, 2026 23:32

@JunyiXu-nv JunyiXu-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Overall LGTM

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56729 [ run ] completed with state SUCCESS. Commit: 25dc000
/LLM/main/L0_MergeRequest_PR pipeline #45549 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

@2ez4bz

2ez4bz commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56823 [ run ] triggered by Bot. Commit: 25dc000 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56823 [ run ] completed with state SUCCESS. Commit: 25dc000
/LLM/main/L0_MergeRequest_PR pipeline #45639 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

@2ez4bz 2ez4bz enabled auto-merge (squash) July 1, 2026 06:11
@2ez4bz

2ez4bz commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56858 [ run ] triggered by Bot. Commit: 25dc000 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56858 [ run ] completed with state SUCCESS. Commit: 25dc000
/LLM/main/L0_MergeRequest_PR pipeline #45670 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

@2ez4bz

2ez4bz commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56969 [ run ] triggered by Bot. Commit: 25dc000 Link to invocation

@2ez4bz 2ez4bz disabled auto-merge July 1, 2026 16:40
@2ez4bz 2ez4bz enabled auto-merge (squash) July 1, 2026 16:40
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56969 [ run ] completed with state SUCCESS. Commit: 25dc000
/LLM/main/L0_MergeRequest_PR pipeline #45771 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

@2ez4bz

2ez4bz commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

* Why?

tau2-bench required a workaround that could misreport errors.

* What?

This commit fixes that with typed checks and adds tests for it.

Signed-off-by: William Zhang <133824995+2ez4bz@users.noreply.github.com>
@2ez4bz 2ez4bz force-pushed the dev-nvbug-6384951 branch from 25dc000 to 739d576 Compare July 2, 2026 04:18
@2ez4bz

2ez4bz commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57109 [ run ] triggered by Bot. Commit: 739d576 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57109 [ run ] completed with state FAILURE. Commit: 739d576
/LLM/main/L0_MergeRequest_PR pipeline #45896 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

@2ez4bz

2ez4bz commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57132 [ run ] triggered by Bot. Commit: 739d576 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57132 [ run ] completed with state SUCCESS. Commit: 739d576
/LLM/main/L0_MergeRequest_PR pipeline #45917 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

@2ez4bz

2ez4bz commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57236 [ run ] triggered by Bot. Commit: 739d576 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57236 [ run ] completed with state SUCCESS. Commit: 739d576
/LLM/main/L0_MergeRequest_PR pipeline #46003 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

@2ez4bz

2ez4bz commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57249 [ run ] triggered by Bot. Commit: 739d576 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57249 [ run ] completed with state FAILURE. Commit: 739d576
/LLM/main/L0_MergeRequest_PR pipeline #46016 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

@2ez4bz

2ez4bz commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

1 similar comment
@yiqingy0

yiqingy0 commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57340 [ run ] triggered by Bot. Commit: 739d576 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57340 [ run ] completed with state FAILURE. Commit: 739d576
/LLM/main/L0_MergeRequest_PR pipeline #46095 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

@2ez4bz

2ez4bz commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57482 [ run ] triggered by Bot. Commit: 739d576 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57482 [ run ] completed with state SUCCESS. Commit: 739d576
/LLM/main/L0_MergeRequest_PR pipeline #46216 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

@2ez4bz

2ez4bz commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57516 [ run ] triggered by Bot. Commit: 739d576 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.

5 participants