Skip to content

Conversation

@erhuve
Copy link
Contributor

@erhuve erhuve commented Oct 10, 2025

Closes #3118

…ments, check if args actually are incomplete or not
@erhuve erhuve force-pushed the feat/ray/tool-exceeds-token-limit-error branch from 4ec19d6 to 537d6ce Compare October 13, 2025 21:13
@erhuve erhuve requested a review from DouweM October 13, 2025 21:14
try:
tool_call.args_as_dict()
except Exception:
raise exceptions.ToolExceedsTokenLimitError(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be a subclass of UnexpectedModelBehavior for backward compatibility, and I suggest renaming it IncompleteToolCall

# as the empty response and request will not create any items in the API payload,
# in the hope the model will return a non-empty response this time.
ctx.state.increment_retries(ctx.deps.max_result_retries)
max_tokens = (ctx.deps.model_settings or {}).get('max_tokens') if ctx.deps.model_settings else None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we pass in the entire model_settings object to clean these repeated sections up a bit?

…ckwards compat, simplify by passing in model settings instead of determining tokens on each call of increment_retries
@DouweM DouweM changed the title Add exception for tool output exceeding token limit Raise IncompleteToolCall when token limit is reached during generation of tool call Oct 21, 2025
@DouweM DouweM enabled auto-merge (squash) October 21, 2025 16:10
@DouweM
Copy link
Collaborator

DouweM commented Oct 21, 2025

@erhuve Thank you!

@DouweM DouweM merged commit 9d20769 into pydantic:main Oct 21, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better handling when max tokens limit results in incomplete tool call arguments

2 participants