Skip to content

Make sys.stdout/stderr filtering opt-in#4585

Open
thakoreh wants to merge 2 commits intocrewAIInc:mainfrom
thakoreh:make-filtered-stream-opt-in
Open

Make sys.stdout/stderr filtering opt-in#4585
thakoreh wants to merge 2 commits intocrewAIInc:mainfrom
thakoreh:make-filtered-stream-opt-in

Conversation

@thakoreh
Copy link
Copy Markdown

Description

Fixes #3000 - Stop hijacking sys.stdout and sys.stderr

Problem

The FilteredStream was unconditionally wrapping sys.stdout and sys.stderr at module import time, affecting all code that imports crewai.llm. This is a global side effect that library code should not impose on users.

As noted in Python docs for contextlib.redirect_stdout:

Note that the global side effect on sys.stdout means that this context manager is not suitable for use in library code

Solution

Make the filtering opt-in:

  • Added environment variable CREWAI_FILTER_LITELLM_OUTPUT (set to 1/true/yes to enable)
  • Added enable_litellm_filtering() helper for programmatic use
  • Users who want the old behavior can set the env var

Changes

  • Filtering now requires explicit opt-in
  • Added enable_litellm_filtering() public helper function
  • Maintained backward compatibility for users who set the env var

The FilteredStream was unconditionally wrapping sys.stdout and sys.stderr
at module import time, affecting all code that imports crewai.llm. This is
a global side effect that library code should not impose on users.

Changes:
- Filtering is now opt-in via CREWAI_FILTER_LITELLM_OUTPUT env var
- Added enable_litellm_filtering() helper function for programmatic use
- Users who want the old behavior can set CREWAI_FILTER_LITELLM_OUTPUT=1

Fixes: crewAIInc#3000
@github-actions
Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 45 days with no activity.

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.

[FEATURE] Stop hijacking sys.stdout and sys.stderr

1 participant