run-llama/llama_index · warning · ValueError

Could not extract final answer from input text: {input_text}

Error message

Could not extract final answer from input text: {input_text}

What it means

BaseKeyValueStore.put_all's default implementation only supports batch_size == 1; any caller requesting a larger batch against a store that did not override put_all gets NotImplementedError. Concrete stores (MongoDBKVStore, RedisKVStore, etc.) override this to do real batched writes; the base-class loop is a fallback that writes pairs one by one.

Source

Thrown at llama-index-core/llama_index/core/agent/react/output_parser.py:40

    thought = (match.group(1) or match.group(2)).strip()
    action = match.group(3).strip()
    action_input = match.group(4).strip()
    return thought, action, action_input


def action_input_parser(json_str: str) -> dict:
    processed_string = re.sub(r"(?<!\w)\'|\'(?!\w)", '"', json_str)
    pattern = r'"(\w+)":\s*"([^"]*)"'
    matches = re.findall(pattern, processed_string)
    return dict(matches)


def extract_final_response(input_text: str) -> Tuple[str, str]:
    pattern = r"\s*Thought:(.*?)Answer:(.*?)(?:$)"

    match = re.search(pattern, input_text, re.DOTALL)
    if not match:
        raise ValueError(
            f"Could not extract final answer from input text: {input_text}"
        )

    thought = match.group(1).strip()
    answer = match.group(2).strip()
    return thought, answer


def parse_action_reasoning_step(output: str) -> ActionReasoningStep:
    """
    Parse an action reasoning step from the LLM output.
    """
    # Weaker LLMs may generate ReActAgent steps whose Action Input are horrible JSON strings.
    # `dirtyjson` is more lenient than `json` in parsing JSON strings.
    import dirtyjson as json

    thought, action, action_input = extract_tool_use(output)
    json_str = extract_json_str(action_input)

View on GitHub (pinned to afd0fef371)

Solutions

  1. Call put_all without batch_size (default 1) so the base implementation's loop applies.
  2. Override put_all in your custom store to chunk kv_pairs and delegate to self.put per chunk.
  3. Use a built-in store that supports batching (SimpleKVStore, MongoDBKVStore, RedisKVStore) when batch writes matter.
  4. If performance requires batching, implement put_all with the backend's native bulk API.

Example fix

# before
class MyKVStore(BaseKeyValueStore):
    ...
store.put_all(pairs, batch_size=64)  # NotImplementedError

# after
class MyKVStore(BaseKeyValueStore):
    def put_all(self, kv_pairs, collection=DEFAULT_COLLECTION, batch_size=1):
        for key, val in kv_pairs:  # simple unbatched fallback
            self.put(key, val, collection=collection)
store.put_all(pairs)  # default batch_size=1, works
Defensive patterns

Strategy: validation

Validate before calling

if batch_size != 1 and type(kvstore).put_all is BaseKeyValueStore.put_all:
    kvstore.put_all(kv_pairs)  # fall back to batch_size=1
else:
    kvstore.put_all(kv_pairs, batch_size=batch_size)

Type guard

from llama_index.core.storage.kvstore.types import BaseKeyValueStore

def supports_batching(store: BaseKeyValueStore) -> bool:
    return type(store).put_all is not BaseKeyValueStore.put_all

Try / catch

try:
    kvstore.put_all(pairs, batch_size=64)
except NotImplementedError:
    kvstore.put_all(pairs)  # default batch_size=1

Prevention

When it happens

Trigger: Calling kvstore.put_all(kv_pairs, batch_size=8) on a store whose class only implements the abstract put/get/delete (e.g. a custom KV store or SimpleKVStore without a put_all override); passing DEFAULT_BATCH_SIZE from a config that is greater than 1.

Common situations: Writing a custom KVStore subclass and forgetting to override put_all while the docstore/index store layer tries batched ingestion; swapping a MongoDB-backed store for a minimal in-memory store in tests without implementing batching; configurations that tune batch_size for throughput.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/58ed16662d9fc3e1. Report an issue: GitHub.