{"record":{"id":"36259174fcce47e2","repo":"apache/beam","slug":"expected-text-content-in-type-item-name-item-id-got-none","errorCode":null,"errorMessage":"Expected text content in {type(item).__name__} {item.id}, got None","messagePattern":"Expected text content in (.+?) (.+?), got None","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/rag/embeddings/base.py","lineNumber":55,"sourceCode":"  results back as Embedding objects.\n\n  Returns:\n      EmbeddingTypeAdapter configured for text embedding\n  \"\"\"\n  return EmbeddingTypeAdapter(\n      input_fn=_extract_text, output_fn=_add_embedding_fn)\n\n\n# Backward compatibility alias.\ncreate_rag_adapter = create_text_adapter\n\n\ndef _extract_text(items: Sequence[EmbeddableItem]) -> list[str]:\n  \"\"\"Extract text from items for embedding.\"\"\"\n  texts = []\n  for item in items:\n    if not item.content.text:\n      raise ValueError(\n          f\"Expected text content in {type(item).__name__} {item.id}, \"\n          \"got None\")\n    texts.append(item.content.text)\n  return texts\n\n\ndef _add_embedding_fn(\n    items: Sequence[EmbeddableItem],\n    embeddings: Sequence[list[float]]) -> list[EmbeddableItem]:\n  \"\"\"Create Embeddings from items and embedding vectors.\"\"\"\n  for item, embedding in zip(items, embeddings):\n    item.embedding = Embedding(dense_embedding=embedding)\n  return list(items)\n","sourceCodeStart":37,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/rag/embeddings/base.py#L37-L69","documentation":"_extract_text in apache_beam.ml.rag.embeddings.base raises this ValueError when an EmbeddableItem in the batch has no content.text (None or empty). The helper collects text strings for embedding calls, and embedding APIs require non-empty text, so items lacking text are rejected with an error identifying the item's class and id. It runs inside the batching path of the embedding PTransform, so it surfaces at pipeline runtime on workers.","triggerScenarios":"Featuring an input document whose text field was never set (e.g. dict missing the mapped text key, or content.text=None) and passing it through an embeddings manager like VertexAITextEmbeddings or HuggingfaceTextEmbeddings; upstream transforms producing empty records; JSON/CSV rows with null text columns.","commonSituations":"ETL producing documents where the text field name changed (doc['content'] vs doc['contents']); filtered/empty records from a database; files that failed parsing upstream yielding empty text; passing image-only items to a text embeddings manager.","solutions":["Filter out or fill items with missing text before the embedding transform: beam.Filter(lambda x: x.content.text).","Fix upstream extraction so content.text is populated for every item.","Route image-only items to an image embeddings manager (e.g. HuggingfaceImageEmbeddings) instead of a text one.","Log/inspect item.id from the error message to find the offending record at the source."],"exampleFix":"// before\nembedded = pcoll | embedder\n\n// after\nembedded = (pcoll\n    | beam.Filter(lambda item: item.content.text)\n    | embedder)","handlingStrategy":"validation","validationCode":"import apache_beam as beam\n\ndef filter_items_without_text(pcoll):\n    return pcoll | 'DropEmptyText' >> beam.Filter(\n        lambda item: bool(item.content and item.content.text))","typeGuard":"def has_text(item) -> bool:\n    content = getattr(item, 'content', None)\n    return bool(content is not None and getattr(content, 'text', None))","tryCatchPattern":"try:\n    result = pcoll | embedder\nexcept ValueError as e:\n    # e.g. 'Expected text content in EmbeddableItem <id>, got None'\n    logging.error('Embedding input missing text: %s', e)\n    raise","preventionTips":["Always beam.Filter out null/empty text before embedding transforms.","Keep the text key in record-building code in sync with the embeddings config.","Assert content.text in unit tests for your document-producing transforms."],"tags":["python","apache-beam","valueerror","embeddings","null-content"],"backgroundTag":"null-argument","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"}