fix(core): return 400 for ContextWindowExceededError instead of 500 (#9348)

SystemPromptTokenExceededError (a subclass of ContextWindowExceededError)
was hitting the generic 500 handler in Datadog. This is a client-side
configuration issue (system prompt too large for context window), so it
should return 400 Bad Request.

Datadog: https://us5.datadoghq.com/error-tracking/issue/3360e252-d5f1-11f0-8467-da7ad0900000
Also covers: https://us5.datadoghq.com/error-tracking/issue/6e50c57c

🤖 Generated with [Letta Code](https://letta.com)

Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
Kian Jones
2026-02-06 17:11:51 -08:00
committed by Caren Thomas
parent 47aedfa1a7
commit 32d87b70d7

View File

@@ -33,6 +33,7 @@ from letta.errors import (
AgentNotFoundForExportError,
BedrockPermissionError,
ConcurrentUpdateError,
ContextWindowExceededError,
ConversationBusyError,
EmbeddingConfigRequiredError,
HandleNotFoundError,
@@ -513,6 +514,7 @@ def create_application() -> "FastAPI":
app.add_exception_handler(AgentFileImportError, _error_handler_400)
app.add_exception_handler(EmbeddingConfigRequiredError, _error_handler_400)
app.add_exception_handler(LettaImageFetchError, _error_handler_400)
app.add_exception_handler(ContextWindowExceededError, _error_handler_400)
app.add_exception_handler(ValueError, _error_handler_400)
# 404 Not Found errors