{"record":{"id":"1a623f914f1d43bf","repo":"stanford-oval/storm","slug":"snippet-index-out-of-range","errorCode":null,"errorMessage":"Snippet index out of range","messagePattern":"Snippet index out of range","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"knowledge_storm/collaborative_storm/modules/collaborative_storm_utils.py","lineNumber":27,"sourceCode":"    from ..engine import RunnerArgument\r\nfrom ...interface import Information, Retriever, LMConfigs\r\nfrom ...logging_wrapper import LoggingWrapper\r\nfrom ...rm import BingSearch\r\n\r\n\r\ndef extract_storm_info_snippet(info: Information, snippet_index: int) -> Information:\r\n    \"\"\"\r\n    Constructs a new Information instance with only the specified snippet index.\r\n\r\n    Args:\r\n        storm_info (Information): The original Information instance.\r\n        snippet_index (int): The index of the snippet to retain.\r\n\r\n    Returns:\r\n        Information: A new Information instance with only the specified snippet.\r\n    \"\"\"\r\n    if snippet_index < 0 or snippet_index >= len(info.snippets):\r\n        raise ValueError(\"Snippet index out of range\")\r\n\r\n    new_snippets = [info.snippets[snippet_index]]\r\n    new_storm_info = Information(\r\n        info.url, info.description, new_snippets, info.title, info.meta\r\n    )\r\n    return new_storm_info\r\n\r\n\r\ndef format_search_results(\r\n    searched_results: List[Information],\r\n    info_max_num_words: int = 1000,\r\n    mode: str = \"brief\",\r\n) -> Tuple[str, Dict[int, Information]]:\r\n    \"\"\"\r\n    Constructs a string from a list of search results with a specified word limit and returns a mapping of indices to Information.\r\n\r\n    Args:\r\n        searched_results (List[Information]): List of Information objects to process.\r","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/stanford-oval/storm/blob/fb951af7744dab086e34962e9bc6fe878e145f83/knowledge_storm/collaborative_storm/modules/collaborative_storm_utils.py#L9-L45","documentation":"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).","triggerScenarios":"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.","commonSituations":"LLM outputs an index that assumes 1-based counting, stale indices after information was re-created/filtered, or an Information constructed with empty snippets.","solutions":["Validate/correct the index before calling: use max(0, min(i, len(info.snippets)-1)) or convert 1-based to 0-based","Skip the snippet when info.snippets is empty instead of indexing","If indices come from an LLM, parse and clamp/validate its numeric output"],"exampleFix":"# before\nnew_info = extract_storm_info_snippet(info, idx)  # idx may be out of range\n\n# after\nif not info.snippets:\n    return None\nidx = idx if 0 <= idx < len(info.snippets) else 0\nnew_info = extract_storm_info_snippet(info, idx)","handlingStrategy":"validation","validationCode":"def safe_snippet(info, idx):\n    if not info.snippets:\n        return None\n    return extract_storm_info_snippet(info, min(max(idx, 0), len(info.snippets) - 1))","typeGuard":"def has_snippet(info, idx) -> bool:\n    return 0 <= idx < len(info.snippets)","tryCatchPattern":"try:\n    new_info = extract_storm_info_snippet(info, idx)\nexcept ValueError:\n    new_info = info  # or skip","preventionTips":["Clamp LLM-provided indices to the snippet range","Guard against empty snippets","Convert 1-based model output to 0-based"],"tags":["index-out-of-range","snippets","validation"],"backgroundTag":"index-out-of-bounds","analyzedSha":"fb951af7744dab086e34962e9bc6fe878e145f83","analyzedAt":"2026-08-28T11:56:54.780Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}