-
-
Notifications
You must be signed in to change notification settings - Fork 79
Open
Enhancement
Copy link
Description
What feature do you want to see added?
Problem
ChatRequest.message currently only validates that the message is not empty (schemas.py:48). there is no upper bound on message length. this means a user can submit an arbitrarily large string (e.g., 1MB) via:
POST /sessions/{id}/message(REST)WS /sessions/{id}/stream(WebSocket — no validation at all onmessage_data.get("message"))
the oversized input flows directly into the LLM pipeline (generate_answer()), where it either silently overflows the context window (context_length: 2048 in config) or wastes compute on prompt construction, embedding, and retrieval for content that can't be processed.
by contrast, the file upload path already enforces MAX_TEXT_CONTENT_LENGTH = 10000 in file_service.py, so there is precedent for input bounds - but the primary chat path has none.
Proposed fix
- add a
max_lengthconstraint toChatRequest.messageinschemas.pyusing Pydantic'sField(max_length=...)or a custom@field_validator. - add the same check in the WebSocket handler (
chatbot_stream) foruser_messagebefore callingget_chatbot_reply_stream(). - make the limit configurable via
config.yml(e.g.,chat.max_message_length: 5000). - return a clear
422error for REST and a JSON error message for WebSocket when exceeded.
Impact
- prevents resource abuse on the LLM pipeline
- aligns chat input validation with the existing file upload guardrails
- improves API contract clarity for frontend clients
Upstream changes
No response
Are you interested in contributing this feature?
Yes..
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for Enhancement.