From 32d87b70d7613d0f33527f6cef2842df63871de1 Mon Sep 17 00:00:00 2001 From: Kian Jones <11655409+kianjones9@users.noreply.github.com> Date: Fri, 6 Feb 2026 17:11:51 -0800 Subject: [PATCH] fix(core): return 400 for ContextWindowExceededError instead of 500 (#9348) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- letta/server/rest_api/app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/letta/server/rest_api/app.py b/letta/server/rest_api/app.py index 91d8905f..e984a37e 100644 --- a/letta/server/rest_api/app.py +++ b/letta/server/rest_api/app.py @@ -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