{"record":{"id":"9145e24140e9d211","repo":"langchain-ai/langchain","slug":"unsupported-hashing-algorithm-algorithm","errorCode":null,"errorMessage":"Unsupported hashing algorithm: {algorithm}","messagePattern":"Unsupported hashing algorithm: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/indexing/api.py","lineNumber":172,"sourceCode":"    \"\"\"Raised when an indexing operation fails.\"\"\"\n\n\ndef _calculate_hash(\n    text: str, algorithm: Literal[\"sha1\", \"sha256\", \"sha512\", \"blake2b\"]\n) -> str:\n    \"\"\"Return a hexadecimal digest of *text* using *algorithm*.\"\"\"\n    if algorithm == \"sha1\":\n        # Calculate the SHA-1 hash and return it as a UUID.\n        digest = hashlib.sha1(text.encode(\"utf-8\"), usedforsecurity=False).hexdigest()\n        return str(uuid.uuid5(NAMESPACE_UUID, digest))\n    if algorithm == \"blake2b\":\n        return hashlib.blake2b(text.encode(\"utf-8\")).hexdigest()\n    if algorithm == \"sha256\":\n        return hashlib.sha256(text.encode(\"utf-8\")).hexdigest()\n    if algorithm == \"sha512\":\n        return hashlib.sha512(text.encode(\"utf-8\")).hexdigest()\n    msg = f\"Unsupported hashing algorithm: {algorithm}\"  # type: ignore[unreachable]\n    raise ValueError(msg)\n\n\ndef _get_document_with_hash(\n    document: Document,\n    *,\n    key_encoder: Callable[[Document], str]\n    | Literal[\"sha1\", \"sha256\", \"sha512\", \"blake2b\"],\n) -> Document:\n    \"\"\"Calculate a hash of the document, and assign it to the uid.\n\n    When using one of the predefined hashing algorithms, the hash is calculated\n    by hashing the content and the metadata of the document.\n\n    Args:\n        document: Document to hash.\n        key_encoder: Hashing algorithm to use for hashing the document.\n            If not provided, a default encoder using SHA-1 will be used.\n            SHA-1 is not collision-resistant, and a motivated attacker","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/indexing/api.py#L154-L190","documentation":"Raised by `_calculate_hash` in `langchain_core.indexing.api`. The indexing API hashes document content and metadata to detect changes; supported algorithms are sha1, sha256, sha512, and blake2b. The parameter is typed as a Literal, so in a well-typed program this branch is unreachable (`# type: ignore[unreachable]`), but at runtime an arbitrary string reaches it and is rejected.","triggerScenarios":"Passing `index(..., key_encoder=\"md5\")` or any algorithm name outside the Literal set; passing `hash_algorithm`/`key_encoder` from user config without validation; version skew where an older code path forwards a raw string.","commonSituations":"Security policies that mandate a specific hash (e.g. trying md5/sha384); config files shared across tools where the algorithm field is free-text; typos like \"sha-256\" instead of \"sha256\".","solutions":["Use one of the supported names exactly: \"sha1\", \"sha256\", \"sha512\", or \"blake2b\".","If you need a custom digest, pass a callable `key_encoder=lambda doc: ...` instead of an algorithm string.","Validate the config value against the allowed set at startup."],"exampleFix":"# before\nindex(vs, docs, rm, key_encoder=\"sha-256\", cleanup=\"full\")\n\n# after\nindex(vs, docs, rm, key_encoder=\"sha256\", cleanup=\"full\")","handlingStrategy":"validation","validationCode":"ALLOWED = {\"sha1\", \"sha256\", \"sha512\", \"blake2b\"}\nif key_encoder not in ALLOWED and not callable(key_encoder):\n    raise ValueError(f\"algorithm must be one of {sorted(ALLOWED)} or a callable\")\nindex(vs, docs, rm, key_encoder=key_encoder, cleanup=\"full\")","typeGuard":"def is_supported_algorithm(name: str) -> bool:\n    return name in {\"sha1\", \"sha256\", \"sha512\", \"blake2b\"}","tryCatchPattern":null,"preventionTips":["Type config fields as Literal[\"sha1\",\"sha256\",\"sha512\",\"blake2b\"] in your settings model.","Watch for hyphenated names like 'sha-256' from user input; normalize before passing."],"tags":["indexing","hashing","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}