{"record":{"id":"fb52d515ad15c512","repo":"langchain-ai/langchain","slug":"could-not-resolve-content-key-full-path-r-missi","errorCode":null,"errorMessage":"Could not resolve content_key {full_path!r}: missing key {key!r} under {current_path!r}.","messagePattern":"Could not resolve content_key (.+?): missing key (.+?) under (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/document_loaders/langsmith.py","lineNumber":171,"sourceCode":"    content = inputs\n    full_path = \".\".join(content_key)\n\n    for i, key in enumerate(content_key):\n        current_path = \".\".join(content_key[:i]) or \"<root>\"\n        if not isinstance(content, Mapping):\n            msg = (\n                f\"Could not resolve content_key {full_path!r}: expected a mapping at \"\n                f\"{current_path!r}, but found {type(content).__name__}.\"\n            )\n            # A too-deep `content_key` is an invalid-argument error, not a runtime\n            # type bug, so it is unified with the missing-key case as `ValueError`.\n            raise ValueError(msg)  # noqa: TRY004\n        if key not in content:\n            msg = (\n                f\"Could not resolve content_key {full_path!r}: missing key {key!r} \"\n                f\"under {current_path!r}.\"\n            )\n            raise ValueError(msg)\n        content = content[key]\n\n    return content\n\n\ndef _stringify(x: str | dict[str, Any]) -> str:\n    if isinstance(x, str):\n        return x\n    try:\n        return json.dumps(x, indent=2)\n    except Exception:\n        return str(x)\n","sourceCodeStart":153,"sourceCodeEnd":184,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/document_loaders/langsmith.py#L153-L184","documentation":"While resolving `content_key` on a LangSmith dataset example, a path segment does not exist in the mapping at that level: `ValueError` names the full key, the missing segment, and the path traversed so far. The loader refuses to guess when a required key is absent from the example inputs.","triggerScenarios":"`content_key='answer.text'` where examples have inputs `{'answer': {...no 'text'...}}`; key typo or casing mismatch ('Text' vs 'text'); heterogeneous datasets where only some examples carry the key; schema drift after dataset version updates.","commonSituations":"Renamed fields in a re-uploaded dataset; guessing key names from memory; mixed-format datasets where optional fields are omitted on some examples.","solutions":["Print an example's structure (`example.inputs.keys()` / pprint) and correct the content_key spelling/path","If the key is optional on some examples, switch to `format_content` — supply a callable that tolerates absence — or pre-normalize the dataset","Re-upload/fix the dataset so every example contains the required key","Guard the whole load with try/except ValueError to surface dataset-name + key together for debugging"],"exampleFix":"# before\nloader = LangSmithLoader(dataset_name=\"ds\", content_key=\"output_text\")\n\n# after\nloader = LangSmithLoader(\n    dataset_name=\"ds\",\n    content_key=\"answer\",\n    format_content=lambda x: x.get(\"output_text\", \"\") if isinstance(x, dict) else str(x),\n)","handlingStrategy":"validation","validationCode":"def key_exists(inputs: dict, content_key: str) -> bool:\n    node = inputs\n    for seg in content_key.split('.'):\n        if not isinstance(node, dict) or seg not in node:\n            return False\n        node = node[seg]\n    return True\n\nassert key_exists(example.inputs, content_key), f'missing {content_key}'","typeGuard":null,"tryCatchPattern":"try:\n    docs = list(loader.lazy_load())\nexcept ValueError as e:\n    if 'missing key' in str(e):\n        logger.error('dataset %s lacks key %s on some examples; normalize or use format_content', dataset, content_key)\n    raise","preventionTips":["Print example.inputs.keys() when choosing content_key","For optional fields, use format_content with a tolerant callable instead of content_key","Keep dataset schemas stable across versions, or re-verify keys after each re-upload"],"tags":["langsmith","document-loader","configuration","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}