fix(spend-logs): redact echoed prompts in error_information#27689
Conversation
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Spend-log error sanitization addedThis PR sanitizes Status: 0 open |
Greptile SummaryThis PR fixes a privacy/size regression where provider validation errors (notably OpenAI pydantic errors carrying
Confidence Score: 5/5Safe to merge — the change is tightly scoped to the spend-log write path, addresses both issues raised in the previous review threads, and is backed by comprehensive unit tests. The balanced-bracket parser correctly handles nested multimodal payloads and escaped quotes; redaction now covers both No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/proxy/spend_tracking/spend_tracking_utils.py | Adds _scan_balanced_value_end, _redact_prompt_leaks_in_error_string, and _sanitize_error_information_for_spend_logs; the balanced-bracket parser correctly handles nested multimodal content and escaped quotes; redaction covers both error_message and traceback; DB-size cap is always applied. |
| litellm/proxy/hooks/proxy_track_cost_callback.py | Calls _sanitize_error_information_for_spend_logs after the existing traceback-suppression step and before the metadata is persisted; ordering is correct. |
| tests/test_litellm/proxy/spend_tracking/test_spend_tracking_utils.py | Adds 14 new unit tests covering Python repr, JSON, nested multimodal content, escaped quotes, unterminated values, the LIT-2992 reproduction scenario, and the opt-in/opt-out flag; all tests use mocks and make no real network calls per repo policy. |
Reviews (2): Last reviewed commit: "fix(spend-logs): redact echoed prompts i..." | Re-trigger Greptile
330c670 to
02ff466
Compare
|
@yassin-berriai — heads up that the required (There are also a few (Posted automatically by the daily-top-10-prs scheduled task.) |
ba9d3ff to
4d4409c
Compare
4d4409c to
a77258b
Compare
Provider validation errors (e.g. OpenAI RateLimitError carrying 178
pydantic errors each with their own 'input': [...]) were stored verbatim
in LiteLLM_SpendLogs.metadata.error_information.error_message via
str(original_exception), producing rows >12 MB.
Sanitize before metadata is serialized:
- redact 'input'/'messages' values in both error_message and traceback
when store_prompts_in_spend_logs is False (back-door leak paths)
- always apply the MAX_STRING_LENGTH_PROMPT_IN_DB size cap to
error_message and traceback (DB-storage safeguard)
Value scanning uses a parser-based balanced-bracket walk that respects
string quoting, so multi-modal payloads ('messages': [{'content': [...]}])
and user text containing literal brackets ("secret[123") are handled
correctly instead of leaking past a depth-1 regex.
Scoped to the spend-log path so OTEL/Datadog/etc. callbacks still
receive the untruncated error per LITELLM_TRUNCATION_DB_SAFEGUARD_NOTE.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
a77258b to
b327b47
Compare
Provider validation errors (e.g. OpenAI RateLimitError carrying 178 pydantic errors each with their own 'input': [...]) were stored verbatim in LiteLLM_SpendLogs.metadata.error_information.error_message via str(original_exception), producing rows >12 MB.
Sanitize before metadata is serialized:
Scoped to the spend-log path so OTEL/Datadog/etc. callbacks still receive the untruncated error per LITELLM_TRUNCATION_DB_SAFEGUARD_NOTE.
Relevant issues
Linear ticket
Resolves LIT-2992
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
Type
🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test
Changes