{"record":{"id":"3c47b9285540a8d5","repo":"zylon-ai/private-gpt","slug":"request-too-large-system-msg","errorCode":"REQUEST_TOO_LARGE_SYSTEM_MSG","errorMessage":"The system prompt length {system_tokens} exceeds the maximum token limit {token_limit}.","messagePattern":"The system prompt length (.+?) exceeds the maximum token limit (.+?)\\.","errorType":"http","errorClass":"Errors.RequestTooLarge","httpStatus":413,"severity":"error","filePath":"private_gpt/server/chat/interceptors/validator_request_interceptor.py","lineNumber":153,"sourceCode":"            or request.system.get_prompt()\n            or None\n        )\n        system_prompt = (\n            \"\\n\".join(\n                [block.text for block in system_prompt_block]\n                if system_prompt_block\n                else []\n            )\n            if system_prompt_block\n            else None\n        )\n        system_tokens = (\n            len(await async_tokenizer(texts=system_prompt, tokenizer_fn=tokenize))\n            if system_prompt\n            else 0\n        )\n        if system_tokens > token_limit:\n            raise Errors.RequestTooLarge(\n                f\"The system prompt length {system_tokens} exceeds the maximum token limit {token_limit}.\",\n                Errors.Codes.REQUEST_TOO_LARGE_SYSTEM_MSG,\n            )\n\n        combined = user_message_tokens + system_tokens\n        if combined > token_limit:\n            raise Errors.RequestTooLarge(\n                f\"The message length {user_message_tokens} and system prompt length {system_tokens} \"\n                f\"exceed the maximum token limit {token_limit}.\"\n            )\n\n        return\n\n    @staticmethod\n    def _extract_text(message: ChatMessage) -> str:\n        \"\"\"Extract normalized text from message blocks.\"\"\"\n        parts = [\n            block.text.strip()","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/server/chat/interceptors/validator_request_interceptor.py#L135-L171","documentation":"Raised when the resolved system prompt (context-stack system prompt joined, falling back to request.system.get_prompt()) alone tokenizes to more than effective_token_limit. Errors.RequestTooLarge with code REQUEST_TOO_LARGE_SYSTEM_MSG. Even a valid user message cannot coexist with a system prompt that alone blows the budget.","triggerScenarios":"Configuring a very large system prompt (long instructions, injected documents as a context-stack layer) while effective_token_limit is small; stacking multiple context layers whose combined system prompt exceeds the limit.","commonSituations":"RAG content placed in the system layer; accumulating context-stack layers across a session until the prompt grows past the limit; lowering the model/context settings without shrinking the stored system prompt.","solutions":["Shorten the system prompt or reduce context-stack system layers until system_tokens <= effective_token_limit.","Raise effective_token_limit in the model/settings configuration.","Move bulky reference content out of the system prompt into retrieval (RAG) or attachments.","Audit context_stack.to_system_prompt() output length at request time and compact layers."],"exampleFix":"# before\ncontext_stack.add_system_layer(huge_prompt_50k_tokens)  # limit 8k\n\n# after\ncontext_stack.add_system_layer(compact_instructions_2k_tokens)","handlingStrategy":"validation","validationCode":"system_prompt = context_stack.to_system_prompt() or request.system.get_prompt()\nsystem_tokens = len(await async_tokenizer(texts=system_prompt, tokenizer_fn=tokenize)) if system_prompt else 0\nassert system_tokens <= effective_token_limit","typeGuard":null,"tryCatchPattern":"try:\n    await chat_facade.create_chat_event_generator(request=request)\nexcept Errors.RequestTooLarge:\n    context_stack.compact_system_layers()  # shrink and retry","preventionTips":["Keep system prompts short; put reference content in retrieval","Token-check each context layer as it is added","Alert when system prompt exceeds a fraction (e.g. 50%) of the limit"],"tags":["validation","tokens","system-prompt","context-window"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}