{"record":{"id":"d08b23c3aeca32c5","repo":"BerriAI/litellm","slug":"expected-document-dict-got-type-document","errorCode":null,"errorMessage":"Expected document dict, got {type(document)}","messagePattern":"Expected document dict, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/ocr/document_intelligence/transformation.py","lineNumber":359,"sourceCode":"        }\n        OR\n        {\n            \"base64Source\": \"base64_encoded_content\"\n        }\n\n        Args:\n            model: Model name\n            document: Document dict from user (Mistral format)\n            optional_params: Already mapped optional parameters\n            headers: Request headers\n\n        Returns:\n            OCRRequestData with JSON data\n        \"\"\"\n        verbose_logger.debug(\"Azure Document Intelligence transform_ocr_request - model: %s\", model)\n\n        if not isinstance(document, dict):\n            raise ValueError(f\"Expected document dict, got {type(document)}\")\n\n        # Extract document URL from Mistral format\n        doc_type: Final = document.get(\"type\")\n        document_url = None\n\n        if doc_type == \"document_url\":\n            document_url = document.get(\"document_url\", \"\")\n        elif doc_type == \"image_url\":\n            document_url = document.get(\"image_url\", \"\")\n        else:\n            raise ValueError(f\"Invalid document type: {doc_type}. Must be 'document_url' or 'image_url'\")\n\n        if not document_url:\n            raise ValueError(\"Document URL is required\")\n\n        # Build Azure DI request\n        data: Final[dict[str, Any]] = {}\n","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/ocr/document_intelligence/transformation.py#L341-L377","documentation":"Raised in transform_ocr_request when the `document` argument for Azure Document Intelligence OCR is not a dict. LiteLLM's OCR interface follows the Mistral format, where document must be a mapping like {'type': 'document_url', 'document_url': ...}; passing a bare string URL, bytes, or a pydantic object hits this check before any request is built.","triggerScenarios":"Calling litellm OCR with document=\"https://example.com/file.pdf\" (plain string), document=b'...', or a non-dict object instead of {'type': 'document_url', 'document_url': 'https://...'} or {'type': 'image_url', 'image_url': 'data:...;base64,...'}.","commonSituations":"Migrating from an SDK that takes a URL string directly; passing a pydantic model that wasn't dumped; forgetting the {'type': ..., url-key} wrapper when copying examples.","solutions":["Wrap the source in a Mistral-style dict: {'type': 'document_url', 'document_url': <url>} for files, or {'type': 'image_url', 'image_url': <url or data URI>} for images.","If building the dict from a pydantic model, call .model_dump() first.","Check the LiteLLM OCR docs example for the exact document shape."],"exampleFix":"# before\nresp = litellm.aocr_document(model=\"azure_ai/doc-intelligence/prebuilt-read\", document=\"https://x.com/f.pdf\")\n\n# after\nresp = litellm.aocr_document(\n    model=\"azure_ai/doc-intelligence/prebuilt-read\",\n    document={\"type\": \"document_url\", \"document_url\": \"https://x.com/f.pdf\"},\n)","handlingStrategy":"type-guard","validationCode":"def is_document_dict(v: object) -> bool:\n    return isinstance(v, dict) and v.get(\"type\") in (\"document_url\", \"image_url\") and bool(v.get(\"document_url\") or v.get(\"image_url\"))","typeGuard":"from typing import TypeIs\n\ndef is_document_dict(v: object) -> TypeIs[dict]:\n    return isinstance(v, dict)","tryCatchPattern":null,"preventionTips":["Always build the document dict with the {'type': ..., url-key} wrapper.","Call .model_dump() on pydantic objects before passing as document."],"tags":["azure","document-intelligence","ocr","validation","request-format"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}