Back to Signal Feed
CodeTracked since May 18, 2026

Fix empty-input ZeroDivisionError in llama_index prompt truncation helpers

The PR fixes a crash path in `PromptHelper.truncate` and `ChatPromptHelper` by adding empty-input guards so `[]` inputs return an empty result instead of reaching `_get_available_chunk_size`, which previously divided by zero.

PromptHelper.truncateChatPromptHelper.atruncateChatPromptHelper.arepackZeroDivisionError

What Happened

  • The PR fixes a crash path in `PromptHelper.truncate` and `ChatPromptHelper` by adding empty-input guards so `[]` inputs return an empty result instead of reaching `_get_available_chunk_size`, which previously divided by zero.
  • The PR fixes a crash path in `PromptHelper.truncate` and `ChatPromptHelper` by adding empty-input guards so `[]` inputs return an empty result instead of reaching `_get_available_chunk_size`, which previously divided by zero.
  • 1 evidence item attached for review.

What is Different

Before

Scattered source updates, isolated context, and manual follow-up across multiple feeds.

Now

Introduced a concrete correctness fix by short-circuiting three prompt-helper methods on empty sequences (`[]`) and preventing integer division by zero in `_get_available_chunk_size`; also added six targeted unit tests for empty-input and non-empty-input behavior.

Why Track This

Why It Matters

Developers using llama_index with dynamic prompts or chat batches that can occasionally become empty will stop seeing hard failures in truncation/repack flows, so inference pipelines keep processing requests as no-op cases instead of aborting with runtime errors. This is implemented by returning `[]` immediately in `PromptHelper.truncate`, `ChatPromptHelper.atruncate`, and `ChatPromptHelper.arepack` when inputs are empty, which bypasses the buggy division step; monitor for any downstream code that previously depended on an exception for empty lists or that assumes a non-empty return contract.

Impact

Developers using llama_index with dynamic prompts or chat batches that can occasionally become empty will stop seeing hard failures in truncation/repack flows, so inference pipelines keep processing requests as no-op cases instead of aborting with runtime errors. This is implemented by returning `[]` immediately in `PromptHelper.truncate`, `ChatPromptHelper.atruncate`, and `ChatPromptHelper.arepack` when inputs are empty, which bypasses the buggy division step; monitor for any downstream code that previously depended on an exception for empty lists or that assumes a non-empty return contract.

What To Watch Next

  • Watch whether PromptHelper.truncate becomes a repeated pattern.
  • Track follow-up changes around LLMOps.
  • Compare future signals against this evidence trail.
  • Re-check risk flags: empty_list_inputs_expected_behavior_change, upstream_expectation_of_exception.
Open Topic TimelineOpen Technical EventOpen Original Sourceempty_list_inputs_expected_behavior_change / upstream_expectation_of_exception / silent_no_op_paths_in_workflows

Supporting Evidence