{"record":{"id":"312a5e9944dede8e","repo":"apache/beam","slug":"document-field-cannot-be-empty","errorCode":null,"errorMessage":"document_field cannot be empty","messagePattern":"document_field cannot be empty","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/rag/chunking/langchain.py","lineNumber":87,"sourceCode":"      ```\n\n    Args:\n      text_splitter: A LangChain TextSplitter instance that defines how\n        documents are split into chunks.\n      metadata_fields: List of field names to copy from input documents to\n        chunk metadata. These fields will be preserved in each chunk created\n        from the document.\n      chunk_id_fn: Optional function that take a Chunk and return str to\n        generate chunk IDs. If not provided, random UUIDs will be used.\n    \"\"\"\n    if not TextSplitter:\n      raise ImportError(\n          \"langchain is required to use LangChainChunker\"\n          \"Please install it with using `pip install langchain`.\")\n    if not isinstance(text_splitter, TextSplitter):\n      raise TypeError(\"text_splitter must be a LangChain TextSplitter\")\n    if not document_field:\n      raise ValueError(\"document_field cannot be empty\")\n    super().__init__(chunk_id_fn)\n    self.text_splitter = text_splitter\n    self.document_field = document_field\n    self.metadata_fields = metadata_fields\n\n  def get_splitter_transform(\n      self\n  ) -> beam.PTransform[beam.PCollection[dict[str, Any]],\n                       beam.PCollection[Chunk]]:\n    return \"Langchain text split\" >> beam.ParDo(\n        _LangChainTextSplitter(\n            text_splitter=self.text_splitter,\n            document_field=self.document_field,\n            metadata_fields=self.metadata_fields))\n\n\nclass _LangChainTextSplitter(beam.DoFn):\n  def __init__(","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/rag/chunking/langchain.py#L69-L105","documentation":"LangChainChunker.__init__ raises this ValueError when the document_field argument is empty (None or empty string). document_field names the key in each input dict that holds the text to split, so without it the chunker cannot locate content in incoming records. Validation happens at construction time so the pipeline fails fast before submission.","triggerScenarios":"Calling LangChainChunker(text_splitter=..., document_field='') or omitting document_field so it defaults to None/empty; building the arg programmatically from config where the field name key is missing.","commonSituations":"YAML/JSON pipeline config with a missing or blank document_field entry; renaming the input record key (e.g. 'content' vs 'contents') and forgetting to update document_field; copying example code and deleting the argument.","solutions":["Pass a non-empty document_field matching the key of the text content in your input dicts (commonly 'contents' for Beam RAG pipelines).","If loading from config, validate the field name exists before constructing the chunker.","Ensure your input PCollection dicts actually contain that key so a later KeyError doesn't occur."],"exampleFix":"// before\nchunker = LangChainChunker(text_splitter=splitter, document_field='')\n\n// after\nchunker = LangChainChunker(text_splitter=splitter, document_field='contents')","handlingStrategy":"validation","validationCode":"def validate_chunker_config(config: dict) -> str:\n    field = config.get('document_field') or ''\n    if not field:\n        raise ValueError('document_field is required and cannot be empty')\n    return field","typeGuard":"def has_document_field(config) -> bool:\n    return bool(isinstance(config, dict) and config.get('document_field'))","tryCatchPattern":"try:\n    chunker = LangChainChunker(text_splitter=splitter, document_field=cfg['document_field'])\nexcept ValueError as e:\n    logging.error('Invalid chunker config: %s', e)\n    raise","preventionTips":["Validate YAML/JSON pipeline configs for required keys before constructing transforms.","Keep document_field consistent with the actual key in your input records.","Add a smoke test that runs one document through the chunker."],"tags":["python","apache-beam","valueerror","rag","empty-argument"],"backgroundTag":"empty-required-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}