{"record":{"id":"f41d9c5a67d42150","repo":"deepset-ai/haystack","slug":"mockdocumentembedder-expects-a-list-of-documents-a","errorCode":null,"errorMessage":"MockDocumentEmbedder expects a list of Documents as input.In case you want to embed a string, please use the MockTextEmbedder.","messagePattern":"MockDocumentEmbedder expects a list of Documents as input\\.In case you want to embed a string, please use the MockTextEmbedder\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"haystack/components/embedders/mock_document_embedder.py","lineNumber":168,"sourceCode":"        if self.embedding is not None:\n            return list(self.embedding)\n        return _deterministic_embedding(text, self.dimension)\n\n    @component.output_types(documents=list[Document], meta=dict[str, Any])\n    def run(self, documents: list[Document]) -> dict[str, Any]:\n        \"\"\"\n        Return the input documents with deterministic embeddings added, without calling any API.\n\n        :param documents: A list of documents to embed.\n        :returns: A dictionary with the following keys:\n            - `documents`: A list of documents with embeddings.\n            - `meta`: Metadata about the (mock) model.\n        :raises TypeError: If `documents` is not a list of `Document` objects.\n        \"\"\"\n        self.warm_up()\n\n        if not isinstance(documents, list) or (documents and not isinstance(documents[0], Document)):\n            raise TypeError(\n                \"MockDocumentEmbedder expects a list of Documents as input. \"\n                \"In case you want to embed a string, please use the MockTextEmbedder.\"\n            )\n\n        texts_to_embed = [self._prepare_text_to_embed(document) for document in documents]\n        new_documents = [\n            replace(document, embedding=self._embed(text))\n            for document, text in zip(documents, texts_to_embed, strict=True)\n        ]\n\n        meta: dict[str, Any] = {\"model\": self.model, \"usage\": _estimate_usage(texts_to_embed)}\n        meta.update(self.meta)\n        return {\"documents\": new_documents, \"meta\": meta}\n\n    @component.output_types(documents=list[Document], meta=dict[str, Any])\n    async def run_async(self, documents: list[Document]) -> dict[str, Any]:\n        \"\"\"\n        Asynchronously return the input documents with deterministic embeddings added, without calling any API.","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/embedders/mock_document_embedder.py#L150-L186","documentation":"MockDocumentEmbedder.run only accepts a list of haystack Document objects. If `documents` is not a list, or the first element is not a Document, it raises this TypeError and points you to MockTextEmbedder for embedding plain strings. It mirrors the type contract of the real OpenAIDocumentEmbedder so mocks are drop-in replacements.","triggerScenarios":"`MockDocumentEmbedder().run(\"some text\")` (a string instead of a list), `.run([\"a\", \"b\"])` (list of strings), or `.run([dict(content=\"x\")])` (raw dicts not wrapped in Document).","commonSituations":"Wiring a TextEmbedder-shaped input into a DocumentEmbedder in a pipeline; forgetting to wrap strings with `Document(content=...)`; tests ported from a text embedder without adapting the input.","solutions":["Pass `[Document(content=\"...\")]` instead of a bare string or list of strings","Use MockTextEmbedder if you actually want to embed a single string","Check the upstream component in your pipeline — you may need a different embedder type"],"exampleFix":"// before\nresult = embedder.run(\"hello world\")\n// after\nresult = embedder.run([Document(content=\"hello world\")])","handlingStrategy":"type-guard","validationCode":"from haystack.dataclasses import Document\nassert isinstance(documents, list) and (not documents or isinstance(documents[0], Document))\nresult = embedder.run(documents)","typeGuard":"def is_document_list(value) -> bool:\n    from haystack.dataclasses import Document\n    return isinstance(value, list) and (len(value) == 0 or isinstance(value[0], Document))","tryCatchPattern":"try:\n    result = embedder.run(documents)\nexcept TypeError:\n    result = embedder.run([Document(content=str(documents))]) if isinstance(documents, str) else None","preventionTips":["Remember: DocumentEmbedders take list[Document], TextEmbedders take str","Wrap strings with Document(content=...) before embedding documents","Check pipeline component connection types — Haystack validates these at connect time"],"tags":["type-error","mock","documents","python"],"backgroundTag":"wrong-input-type","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}