{"record":{"id":"f26e32875ab2ce03","repo":"run-llama/llama_index","slug":"token-limit-must-be-set-and-greater-than-0-f26e32","errorCode":null,"errorMessage":"Token limit must be set and greater than 0.","messagePattern":"Token limit must be set and greater than 0\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/memory/memory.py","lineNumber":270,"sourceCode":"        exclude=True,\n        description=\"The chat store to use for storing messages.\",\n    )\n    session_id: str = Field(\n        default_factory=generate_chat_store_key,\n        description=\"The key to use for storing messages in the chat store.\",\n    )\n\n    @classmethod\n    def class_name(cls) -> str:\n        return \"Memory\"\n\n    @model_validator(mode=\"before\")\n    @classmethod\n    def validate_memory(cls, values: dict) -> dict:\n        # Validate token limit\n        token_limit = values.get(\"token_limit\", -1)\n        if token_limit < 1:\n            raise ValueError(\"Token limit must be set and greater than 0.\")\n\n        tokenizer_fn = values.get(\"tokenizer_fn\")\n        if tokenizer_fn is None:\n            values[\"tokenizer_fn\"] = get_tokenizer()\n\n        if values.get(\"token_flush_size\", -1) < 1:\n            values[\"token_flush_size\"] = int(token_limit * 0.1)\n        elif values.get(\"token_flush_size\", -1) > token_limit:\n            values[\"token_flush_size\"] = int(token_limit * 0.1)\n\n        # validate all blocks have unique names\n        block_names = [block.name for block in values.get(\"memory_blocks\", [])]\n        if len(block_names) != len(set(block_names)):\n            raise ValueError(\"All memory blocks must have unique names.\")\n\n        return values\n\n    @classmethod","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/memory/memory.py#L252-L288","documentation":"Error \"Token limit must be set and greater than 0.\" thrown in run-llama/llama_index.","triggerScenarios":"Thrown at llama-index-core/llama_index/core/memory/memory.py:270 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a positive token_limit when constructing the Memory instance.","Set token_limit to a value greater than 0, e.g. Memory.from_defaults(session_id=..., token_limit=40000)."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}