{"record":{"id":"2c7280beb411aaa6","repo":"run-llama/llama_index","slug":"you-need-to-install-jsonpath-ng-to-use-this-functi","errorCode":null,"errorMessage":"You need to install jsonpath-ng to use this function!","messagePattern":"You need to install jsonpath-ng to use this function!","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/struct_store/json_query.py","lineNumber":72,"sourceCode":"        return llm_output\n\n    return llm_output_parsed\n\n\ndef default_output_processor(llm_output: str, json_value: JSONType) -> Dict[str, str]:\n    \"\"\"Default output processor that extracts values based on JSON Path expressions.\"\"\"\n    # Post-process the LLM output to remove the JSONPath: prefix\n    llm_output = llm_output.replace(\"JSONPath: \", \"\").replace(\"JSON Path: \", \"\").strip()\n\n    # Split the given string into separate JSON Path expressions\n    expressions = [expr.strip() for expr in llm_output.split(\",\")]\n\n    try:\n        from jsonpath_ng.ext import parse  # pants: no-infer-dep\n        from jsonpath_ng.jsonpath import DatumInContext  # pants: no-infer-dep\n    except ImportError as exc:\n        IMPORT_ERROR_MSG = \"You need to install jsonpath-ng to use this function!\"\n        raise ImportError(IMPORT_ERROR_MSG) from exc\n\n    results: Dict[str, str] = {}\n\n    for expression in expressions:\n        try:\n            datum: List[DatumInContext] = parse(expression).find(json_value)\n            if datum:\n                key = expression.split(\".\")[\n                    -1\n                ]  # Extracting \"title\" from \"$.title\", for example\n                results[key] = \", \".join(str(i.value) for i in datum)\n        except Exception as exc:\n            raise ValueError(f\"Invalid JSON Path: {expression}\") from exc\n\n    return results\n\n\nclass JSONQueryEngine(BaseQueryEngine):","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/struct_store/json_query.py#L54-L90","documentation":"default_output_processor in json_query.py parses the LLM's JSONPath output with jsonpath_ng. llama-index-core does not depend on jsonpath-ng, so the import inside the function fails with an ImportError pointing you at the missing optional package.","triggerScenarios":"Using JSONQueryEngine (GPTJSONQueryEngine / legacy JSON query engine) with its default output processor; the import of jsonpath_ng.ext is attempted only when a query runs, so construction succeeds and the first query fails.","commonSituations":"Minimal llama-index installs; CI images without optional deps; upgrading environments where jsonpath-ng was previously installed transitively but no longer is.","solutions":["pip install jsonpath-ng","Add jsonpath-ng to your project's dependency list","If you cannot install it, supply a custom output_parser to the query engine that extracts values without JSONPath"],"exampleFix":"# before\nquery_engine = JSONQueryEngine(json_value=data, sql_table_name='...')\nawait query_engine.aquery('...')  # ImportError at query time\n\n# after\npip install jsonpath-ng\n# (code unchanged)","handlingStrategy":"try-catch","validationCode":"try:\n    import jsonpath_ng  # noqa: F401\n    HAS_JSONPATH = True\nexcept ImportError:\n    HAS_JSONPATH = False\n\nif not HAS_JSONPATH:\n    raise RuntimeError('JSONQueryEngine requires jsonpath-ng: pip install jsonpath-ng')","typeGuard":"def has_jsonpath() -> bool:\n    try:\n        import jsonpath_ng  # noqa: F401\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"try:\n    result = query_engine.query(q)\nexcept ImportError as e:\n    if 'jsonpath-ng' in str(e):\n        raise RuntimeError('install jsonpath-ng or pass a custom output_parser') from e\n    raise","preventionTips":["Add optional extras to requirements when enabling JSON query engines","Smoke-test one query at engine construction time so missing deps fail fast, not at first user query"],"tags":["llama-index","json","missing-dependency","jsonpath"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}