Skip to content

[Bug]: LiteLLM logs certain error messages to stdout instead of stderr #12580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

colesmcintosh
Copy link
Collaborator

Title

Fix error messages being logged to stdout instead of stderr

Relevant issues

Fixes #12525

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

Fixed print statements that were incorrectly outputting error/debug messages to stdout instead of stderr. This was causing issues for applications that expect structured output on stdout.

What was changed:

  1. Modified litellm/litellm_core_utils/exception_mapping_utils.py:

    • Added sys import at the top of the file
    • Changed all print statements in the debug info section to use file=sys.stderr parameter
    • This affects the "Give Feedback / Get Help" and "LiteLLM.Info" messages
  2. Modified litellm/litellm_core_utils/get_llm_provider_logic.py:

    • Added sys import at the top of the file
    • Changed the "Provider List" print statement to use file=sys.stderr parameter
  3. Added tests/test_litellm/test_exception_mapping_stderr.py:

    • Test case test_exception_debug_info_goes_to_stderr: Verifies that debug info is written to stderr, not stdout
    • Test case test_exception_debug_info_suppressed: Verifies that suppression still works correctly

Test Results:

============================= test session starts ==============================
platform darwin -- Python 3.11.13, pytest-7.4.4, pluggy-1.5.0
collected 2 items

tests/test_litellm/test_exception_mapping_stderr.py::test_exception_debug_info_goes_to_stderr PASSED [ 50%]
tests/test_litellm/test_exception_mapping_stderr.py::test_exception_debug_info_suppressed PASSED [100%]

============================== 2 passed in 0.13s ===============================

Impact:

This fix ensures that error/debug messages from LiteLLM don't interfere with applications that expect structured output on stdout, particularly Python scripts that rely on a one-to-one correspondence between stdin input and stdout output.

- Modified exception_mapping_utils.py to print debug info to stderr
- Modified get_llm_provider_logic.py to print provider info to stderr
- Added tests to verify stderr output behavior

Fixes BerriAI#12525
Copy link

vercel bot commented Jul 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 18, 2025 11:29pm

…nts in exception mapping and LLM provider logic. Update tests to verify logging behavior.
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]: LiteLLM logs certain error messages to stdout instead of stderr
2 participants