Teradata Package for LangChain Function Reference - rename_metadata_keys - Teradata® Package for LangChain - Look here for syntax, methods and examples for the functions included in the Teradata langchain-teradata package.
Teradata® Package for LangChain Function Reference
- Deployment
- VantageCloud
- Edition
- Enterprise
- Product
- Teradata® Package for LangChain
- Release Number
- 20.00.00.01
- Published
- December 2025
- ft:locale
- en-US
- ft:lastEdition
- 2025-12-19
- dita:id
- Langchain-Teradata_FxRef_Lake
- Product Category
- Teradata Vantage
- libs.teradata.langchain_teradata.utils.document_utils.rename_metadata_keys = rename_metadata_keys(docs, key_mapping=None, prefix=None)
- DESCRIPTION:
Renames metadata keys in Langchain Document objects. Either a key mapping
dictionary or a prefix for reserved keywords must be provided, but not both.
PARAMETERS:
docs:
Required Argument.
Specifies the document(s) whose metadata keys should be renamed.
Types: Langchain Document object or list of Langchain Document objects.
key_mapping:
Optional Argument.
Specifies a dictionary mapping old key names to new key names.
Types: dict
Example: {"old_key": "new_key", "source": "doc_source"}
prefix:
Optional Argument.
Specifies a prefix to add to reserved keyword metadata keys.
Types: str
Example: "doc_"
RETURNS:
list of modified Langchain Document objects
RAISES:
TeradataMlException: If both or neither key_mapping and prefix are provided.
EXAMPLES:
# Example 1: Using key_mapping
>>> from langchain_core.documents import Document
>>> docs = [Document(page_content="Sample", metadata={"source": "file.pdf"})]
>>> renamed_docs = rename_metadata_keys(docs, key_mapping={"source": "doc_source"})
# Example 2: Using prefix for reserved keywords
>>> docs = [Document(page_content="Sample", metadata={"table": "data"})]
>>> renamed_docs = rename_metadata_keys(docs, prefix="doc_")