Skip to content

Conversation

@Chesars
Copy link
Contributor

@Chesars Chesars commented Nov 27, 2025

Title

fix: streaming with tool_choice allowed_tools fails with pickle error

Relevant issues

Fixes #17192

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard
    requirement
    - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix

Changes

Summary

When using the Responses API with stream=True and tool_choice of type allowed_tools, the streaming fails with:
TypeError: cannot pickle 'pydantic_core._pydantic_core.ValidatorIterator' object. In _handle_logging_completed_response() when calling copy.deepcopy() on the completed response. The tool_choice field contains a Pydantic ValidatorIterator that cannot be serialized with pickle.

Solution

Replace copy.deepcopy() with Pydantic's model_dump() + model_validate() pattern in both async and sync _handle_logging_completed_response() methods.

Files Changed

  • litellm/responses/streaming_iterator.py
  • tests/llm_responses_api_testing/test_base_responses_api_streaming_iterator.py

Test passing

======================== 6 passed, 9 warnings in 0.09s =========================

…ator (BerriAI#17192)

Replace copy.deepcopy with model_dump + model_validate in streaming
iterator logging to handle Pydantic ValidatorIterator objects that
cannot be pickled when tool_choice uses allowed_tools mode.
@vercel
Copy link

vercel bot commented Nov 27, 2025

@Chesars is attempting to deploy a commit to the CLERKIEAI Team on Vercel.

A member of the Team first needs to authorize it.

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.

[Bug]: OpenAI steaming + tool calling broken

1 participant