{"record":{"id":"701deb03eade6b98","repo":"run-llama/llama_index","slug":"chunk-size-chunk-size-is-not-positive","errorCode":null,"errorMessage":"Chunk size {chunk_size} is not positive.","messagePattern":"Chunk size (.+?) is not positive\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/prompt_helper.py","lineNumber":248,"sourceCode":"        return result\n\n    def get_text_splitter_given_prompt(\n        self,\n        prompt: BasePromptTemplate,\n        num_chunks: int = 1,\n        padding: int = DEFAULT_PADDING,\n        llm: Optional[LLM] = None,\n        tools: Optional[List[\"BaseTool\"]] = None,\n    ) -> TokenTextSplitter:\n        \"\"\"\n        Get text splitter configured to maximally pack available context window,\n        taking into account of given prompt, and desired number of chunks.\n        \"\"\"\n        chunk_size = self._get_available_chunk_size(\n            prompt, num_chunks, padding=padding, llm=llm, tools=tools\n        )\n        if chunk_size <= 0:\n            raise ValueError(f\"Chunk size {chunk_size} is not positive.\")\n        chunk_overlap = int(self.chunk_overlap_ratio * chunk_size)\n        return TokenTextSplitter(\n            separator=self.separator,\n            chunk_size=chunk_size,\n            chunk_overlap=chunk_overlap,\n            tokenizer=self._token_counter.tokenizer,\n        )\n\n    def truncate(\n        self,\n        prompt: BasePromptTemplate,\n        text_chunks: Sequence[str],\n        padding: int = DEFAULT_PADDING,\n        llm: Optional[LLM] = None,\n        tools: Optional[List[\"BaseTool\"]] = None,\n    ) -> List[str]:\n        \"\"\"Truncate text chunks to fit available context window.\"\"\"\n        if not text_chunks:","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/prompt_helper.py#L230-L266","documentation":"After PromptHelper computes the available chunk size (available context minus padding and room for num_chunks), it validates the result is positive before building a TokenTextSplitter. A non-positive chunk size means there is no leftover space in the context window to place even one text chunk.","triggerScenarios":"Calling get_text_splitter(prompt, num_chunks, padding=...) when the prompt + num_output already consume the whole window (chained from the same arithmetic as error 200), or when padding/num_chunks eat the remaining budget (chunk_size = available/num_chunks - padding drops to <= 0).","commonSituations":"Large num_output or long prompts against a small context window; requesting many chunks (high num_chunks) so per-chunk budget collapses; big padding values.","solutions":["Fix the underlying budget: raise context_window or reduce num_output so available context is positive (see error 200)","Reduce num_chunks so each chunk gets more tokens","Reduce the padding argument passed to get_text_splitter","Shorten the prompt template so fewer tokens are pre-consumed"],"exampleFix":"# before\nsplitter = prompt_helper.get_text_splitter(prompt, num_chunks=10, padding=DEFAULT_PADDING)\n\n# after\nsplitter = prompt_helper.get_text_splitter(prompt, num_chunks=2, padding=5)","handlingStrategy":"validation","validationCode":"available = helper.context_window - helper._token_counter(prompt) - helper.num_output\nif available <= 0 or (available // num_chunks) - padding <= 0:\n    num_chunks = 1\n    padding = min(padding, max(available - 1, 0))","typeGuard":null,"tryCatchPattern":"try:\n    splitter = prompt_helper.get_text_splitter(prompt, num_chunks, padding=padding)\nexcept ValueError as e:\n    if 'not positive' in str(e):\n        splitter = prompt_helper.get_text_splitter(prompt, num_chunks=1, padding=1)\n    else:\n        raise","preventionTips":["Never request more chunks than the available budget can fund","Treat padding as a small constant (single digits), not a proportion","Unit-test your prompt budget: assert available > 0 before calling get_text_splitter"],"tags":["llama-index","prompt","chunking","context-window"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}