{"record":{"id":"6031d0a44a08457e","repo":"run-llama/llama_index","slug":"could-not-extract-tool-use-from-input-text-input","errorCode":null,"errorMessage":"Could not extract tool use from input text: {input_text}","messagePattern":"Could not extract tool use from input text: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/agent/react/output_parser.py","lineNumber":20,"sourceCode":"\nimport re\nfrom typing import Tuple\n\nfrom llama_index.core.agent.react.types import (\n    ActionReasoningStep,\n    BaseReasoningStep,\n    ResponseReasoningStep,\n)\nfrom llama_index.core.output_parsers.utils import extract_json_str\nfrom llama_index.core.types import BaseOutputParser\n\n\ndef extract_tool_use(input_text: str) -> Tuple[str, str, str]:\n    pattern = r\"(?:\\s*Thought: (.*?)|(.+))\\n+Action: ([^\\n\\(\\) ]+).*?\\n+Action Input: .*?(\\{.*\\})\"\n\n    match = re.search(pattern, input_text, re.DOTALL)\n    if not match:\n        raise ValueError(f\"Could not extract tool use from input text: {input_text}\")\n\n    thought = (match.group(1) or match.group(2)).strip()\n    action = match.group(3).strip()\n    action_input = match.group(4).strip()\n    return thought, action, action_input\n\n\ndef action_input_parser(json_str: str) -> dict:\n    processed_string = re.sub(r\"(?<!\\w)\\'|\\'(?!\\w)\", '\"', json_str)\n    pattern = r'\"(\\w+)\":\\s*\"([^\"]*)\"'\n    matches = re.findall(pattern, processed_string)\n    return dict(matches)\n\n\ndef extract_final_response(input_text: str) -> Tuple[str, str]:\n    pattern = r\"\\s*Thought:(.*?)Answer:(.*?)(?:$)\"\n\n    match = re.search(pattern, input_text, re.DOTALL)","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/agent/react/output_parser.py#L2-L38","documentation":"Raised by legacy_json_to_doc when a legacy-format doc dict's TYPE_KEY matches none of the legacy types it understands (Document, ImageDocument, TextNode, ImageNode, IndexNode, and plain Node). Unlike json_to_doc, this parser is for pre-0.10 storage formats, so hitting it means the record claims a legacy layout but carries a type tag the legacy converter never supported.","triggerScenarios":"Loading a legacy docstore JSON where __type__ is an arbitrary/unregistered string; records written by old custom subclasses of TextNode whose get_type() returned a bespoke value; legacy data that is actually in the NEW format being passed through the legacy path (or vice versa).","commonSituations":"Migrating projects from llama_index <=0.9 to 0.10+; loading archives of old index stores; hand-migrated data where TYPE_KEY was renamed incorrectly; forks that added custom node types in the legacy era.","solutions":["Print doc_dict[TYPE_KEY] for the failing record to see the exact tag.","Confirm which format the file is in and use the matching parser (json_to_doc for current format, legacy_json_to_doc only for true legacy data).","Map the custom tag to TextNode/Document fields manually and rewrite the record.","Rebuild the docstore from source documents with the current version instead of migrating legacy blobs."],"exampleFix":"# before\n# legacy record: {\"__type__\": \"custom_text\", \"__data__\": {...}}\ndoc = legacy_json_to_doc(record)  # ValueError: Unknown doc type\n\n# after\nif record[\"__type__\"] not in {\"document\", \"image_document\", \"text\", \"image\", \"index\", \"node\"}:\n    record[\"__type__\"] = \"text\"  # coerce known-shape records to TextNode\ndoc = legacy_json_to_doc(record)","handlingStrategy":"validation","validationCode":"LEGACY = {\"document\", \"image_document\", \"text\", \"image\", \"index\", \"node\"}\nif record.get(\"__type__\") not in LEGACY:\n    # coerce or reject before calling legacy_json_to_doc","typeGuard":"def is_legacy_type(tag: str) -> bool:\n    return tag in {\"document\", \"image_document\", \"text\", \"image\", \"index\", \"node\"}","tryCatchPattern":"try:\n    doc = legacy_json_to_doc(rec)\nexcept ValueError as e:\n    if \"Unknown doc type\" in str(e):\n        rec[\"__type__\"] = \"text\"\n        doc = legacy_json_to_doc(rec)","preventionTips":["Detect legacy vs current format before choosing a parser.","Map custom legacy node types to TextNode during migration.","Prefer re-ingesting source data over converting legacy stores."],"tags":["docstore","legacy","migration","deserialization"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}