run-llama/llama_index · error · ValueError
Chunk size {chunk_size} is not positive.
Error message
Chunk size {chunk_size} is not positive. What it means
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.
Source
Thrown at llama-index-core/llama_index/core/indices/prompt_helper.py:248
return result
def get_text_splitter_given_prompt(
self,
prompt: BasePromptTemplate,
num_chunks: int = 1,
padding: int = DEFAULT_PADDING,
llm: Optional[LLM] = None,
tools: Optional[List["BaseTool"]] = None,
) -> TokenTextSplitter:
"""
Get text splitter configured to maximally pack available context window,
taking into account of given prompt, and desired number of chunks.
"""
chunk_size = self._get_available_chunk_size(
prompt, num_chunks, padding=padding, llm=llm, tools=tools
)
if chunk_size <= 0:
raise ValueError(f"Chunk size {chunk_size} is not positive.")
chunk_overlap = int(self.chunk_overlap_ratio * chunk_size)
return TokenTextSplitter(
separator=self.separator,
chunk_size=chunk_size,
chunk_overlap=chunk_overlap,
tokenizer=self._token_counter.tokenizer,
)
def truncate(
self,
prompt: BasePromptTemplate,
text_chunks: Sequence[str],
padding: int = DEFAULT_PADDING,
llm: Optional[LLM] = None,
tools: Optional[List["BaseTool"]] = None,
) -> List[str]:
"""Truncate text chunks to fit available context window."""
if not text_chunks:View on GitHub (pinned to afd0fef371)
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
Example fix
# before splitter = prompt_helper.get_text_splitter(prompt, num_chunks=10, padding=DEFAULT_PADDING) # after splitter = prompt_helper.get_text_splitter(prompt, num_chunks=2, padding=5)
Defensive patterns
Strategy: validation
Validate before calling
available = helper.context_window - helper._token_counter(prompt) - helper.num_output
if available <= 0 or (available // num_chunks) - padding <= 0:
num_chunks = 1
padding = min(padding, max(available - 1, 0)) Try / catch
try:
splitter = prompt_helper.get_text_splitter(prompt, num_chunks, padding=padding)
except ValueError as e:
if 'not positive' in str(e):
splitter = prompt_helper.get_text_splitter(prompt, num_chunks=1, padding=1)
else:
raise Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Calculated available context size {context_size_tokens} was
- Configured node parser does not have chunk size.
- Configured node parser does not have chunk overlap.
- First argument to Readability constructor should be a docume
- Aborting parsing document; {numTags} elements found
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/701deb03eade6b98.
Report an issue: GitHub.