stanford-oval/storm · error · ValueError

Snippet index out of range

Error message

Snippet index out of range

What it means

extract_storm_info_snippet tries to build a single-snippet copy of an Information object, and the requested snippet index is negative or >= len(info.snippets).

Source

Thrown at knowledge_storm/collaborative_storm/modules/collaborative_storm_utils.py:27

    from ..engine import RunnerArgument
from ...interface import Information, Retriever, LMConfigs
from ...logging_wrapper import LoggingWrapper
from ...rm import BingSearch


def extract_storm_info_snippet(info: Information, snippet_index: int) -> Information:
    """
    Constructs a new Information instance with only the specified snippet index.

    Args:
        storm_info (Information): The original Information instance.
        snippet_index (int): The index of the snippet to retain.

    Returns:
        Information: A new Information instance with only the specified snippet.
    """
    if snippet_index < 0 or snippet_index >= len(info.snippets):
        raise ValueError("Snippet index out of range")

    new_snippets = [info.snippets[snippet_index]]
    new_storm_info = Information(
        info.url, info.description, new_snippets, info.title, info.meta
    )
    return new_storm_info


def format_search_results(
    searched_results: List[Information],
    info_max_num_words: int = 1000,
    mode: str = "brief",
) -> Tuple[str, Dict[int, Information]]:
    """
    Constructs a string from a list of search results with a specified word limit and returns a mapping of indices to Information.

    Args:
        searched_results (List[Information]): List of Information objects to process.

View on GitHub (pinned to fb951af774)

Solutions

  1. Validate/correct the index before calling: use max(0, min(i, len(info.snippets)-1)) or convert 1-based to 0-based
  2. Skip the snippet when info.snippets is empty instead of indexing
  3. If indices come from an LLM, parse and clamp/validate its numeric output

Example fix

# before
new_info = extract_storm_info_snippet(info, idx)  # idx may be out of range

# after
if not info.snippets:
    return None
idx = idx if 0 <= idx < len(info.snippets) else 0
new_info = extract_storm_info_snippet(info, idx)
Defensive patterns

Strategy: validation

Validate before calling

def safe_snippet(info, idx):
    if not info.snippets:
        return None
    return extract_storm_info_snippet(info, min(max(idx, 0), len(info.snippets) - 1))

Type guard

def has_snippet(info, idx) -> bool:
    return 0 <= idx < len(info.snippets)

Try / catch

try:
    new_info = extract_storm_info_snippet(info, idx)
except ValueError:
    new_info = info  # or skip

Prevention

When it happens

Trigger: Calling extract_storm_info_snippet(info, i) with i beyond the snippet list, or when info.snippets is empty (any index fails the range check). Reached from format_search_results or _get_conv_turn_unused_information when a selected/returned snippet index doesn't match the underlying Information.

Common situations: LLM outputs an index that assumes 1-based counting, stale indices after information was re-created/filtered, or an Information constructed with empty snippets.

Related errors


AI-assisted analysis of stanford-oval/storm@fb951af774 (2026-08-28). Data as JSON: /api/errors/1a623f914f1d43bf. Report an issue: GitHub.