Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit f7ee0af

Browse files
committed
Redact production ValueError responses
1 parent 955216a commit f7ee0af

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎src/api/app.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _public_exception_message(exc: Exception) -> str:
114114
if isinstance(exc, TimeoutError):
115115
return "The request timed out while waiting for an LLM response."
116116
if isinstance(exc, ValueError):
117-
return message or "Invalid request."
117+
return "Invalid request."
118118
if isinstance(exc, ConnectionError):
119119
return "A backend service is unavailable. Check the server logs with the request_id for details."
120120
if isinstance(exc, RuntimeError):

‎tests/api/test_app_errors.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ def test_public_exception_message_redacts_connection_details_in_production(monke
1515
assert "backend service is unavailable" in message
1616

1717

18+
def test_public_exception_message_redacts_value_error_in_production(monkeypatch):
19+
monkeypatch.setattr(api_app.settings, "environment", "production", raising=False)
20+
21+
message = api_app._public_exception_message(
22+
ValueError("vector mismatch for postgresql://user:password@internal-db:5432/xmem")
23+
)
24+
25+
assert message == "Invalid request."
26+
assert "password" not in message
27+
assert "internal-db" not in message
28+
29+
1830
def test_public_exception_message_keeps_timeout_detail_in_local(monkeypatch):
1931
monkeypatch.setattr(api_app.settings, "environment", "development", raising=False)
2032

0 commit comments

Comments
 (0)