{"record":{"id":"8f0a804d3bb75c4e","repo":"langchain-ai/langchain","slug":"could-not-resolve-content-key-full-path-r-expec","errorCode":null,"errorMessage":"Could not resolve content_key {full_path!r}: expected a mapping at {current_path!r}, but found {type(content).__name__}.","messagePattern":"Could not resolve content_key (.+?): expected a mapping at (.+?), but found (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/document_loaders/langsmith.py","lineNumber":165,"sourceCode":"        The extracted content value.\n\n    Raises:\n        ValueError: If a key in `content_key` is missing, or a value along the path\n            (including `inputs` itself) is not a mapping.\n    \"\"\"\n    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)","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/document_loaders/langsmith.py#L147-L183","documentation":"`LangSmithLoader`'s `content_key` path resolver walks the example `inputs` mapping dot-segment by dot-segment; if an intermediate (or root) value along the path is not a `Mapping`, it raises `ValueError` reporting the full path, the offending segment position, and the actual type found. A too-deep or structurally wrong `content_key` is an invalid-argument error, deliberately unified with the missing-key case as `ValueError`.","triggerScenarios":"`LangSmithLoader(dataset_name=..., content_key='inputs.foo.bar')` where `inputs` is a string or `foo` is a list; dataset schemas where the key names fields (`inputs.inputs.msg`) but the actual root already is the inputs mapping (path should then be `msg`, not `inputs.msg`); numeric list indexing attempts like `content_key='messages.0.text'` (lists are not Mappings).","commonSituations":"Datasets whose example shape changed after a re-upload; guessing the content_key without inspecting one example; keys that start with the literal `inputs.` because docs show the stored example envelope rather than the passed mapping; trying to traverse arrays.","solutions":["Inspect one example first: `next(iter(Client().list_examples(dataset_name=...))).inputs` and shape content_key to that structure","Remove a leading `inputs.` segment if your content_key is applied to the inputs mapping itself","Ensure every intermediate step in the path is a dict; for lists, pre-transform the dataset or flatten in `format_content` instead of indexing via content_key","If the schema changed, update or re-upload the dataset and align content_key"],"exampleFix":"# before\n# example.inputs == {\"messages\": [{\"text\": \"hi\"}]}\nloader = LangSmithLoader(dataset_name=\"ds\", content_key=\"inputs.messages\")\n\n# after\nloader = LangSmithLoader(dataset_name=\"ds\", content_key=\"messages\")","handlingStrategy":"validation","validationCode":"from collections.abc import Mapping\n\ndef content_key_valid(inputs: dict, content_key: str) -> bool:\n    node = inputs\n    for seg in content_key.split('.'):\n        if not isinstance(node, Mapping) or seg not in node:\n            return False\n        node = node[seg]\n    return True\n\nexample_inputs = next(iter(client.list_examples(dataset_name=ds))).inputs\nassert content_key_valid(example_inputs, content_key), 'bad content_key'","typeGuard":"from collections.abc import Mapping\n\ndef is_walkable_mapping(value: object) -> bool:\n    \"\"\"True if value can be traversed by a dotted content_key segment.\"\"\"\n    return isinstance(value, Mapping)","tryCatchPattern":"try:\n    docs = list(loader.lazy_load())\nexcept ValueError as e:\n    if 'content_key' in str(e):\n        raise ValueError(f'{dataset}: content_key {content_key!r} does not match schema; '\n                         f'inspect one example's inputs') from e\n    raise","preventionTips":["Always inspect one example's inputs before setting content_key","Remember dotted paths traverse dicts only — flatten lists via format_content","Re-validate content_key whenever a dataset is re-uploaded or versioned"],"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"}