{"record":{"id":"eb9ab6405eb6b0d3","repo":"BerriAI/litellm","slug":"invalid-document-type-doc-type-must-be-docume","errorCode":null,"errorMessage":"Invalid document type: {doc_type}. Must be 'document_url' or 'image_url'","messagePattern":"Invalid document type: (.+?)\\. Must be 'document_url' or 'image_url'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure_ai/ocr/document_intelligence/transformation.py","lineNumber":370,"sourceCode":"\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\n        # Check if it's a data URI (base64)\n        if document_url.startswith(\"data:\"):\n            # Extract base64 content\n            base64_content: Final = self._extract_base64_from_data_uri(document_url)\n            data[\"base64Source\"] = base64_content\n            verbose_logger.debug(\"Using base64Source for Azure Document Intelligence\")\n        else:\n            # Regular URL\n            data[\"urlSource\"] = document_url\n            verbose_logger.debug(\"Using urlSource for Azure Document Intelligence\")\n","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/ocr/document_intelligence/transformation.py#L352-L388","documentation":"Raised when the document dict's `type` field is neither 'document_url' nor 'image_url'. Azure DI transformation only maps these two Mistral-style document kinds onto its analyze request; any other type value (including None when the key is missing) is rejected before the request is built.","triggerScenarios":"Calling azure_ai doc-intelligence OCR with document={'type': 'file', ...}, {'type': 'pdf', ...}, or a dict missing the 'type' key entirely (doc_type becomes None).","commonSituations":"Guessing type names ('url', 'file_url', 'document'); typos; upstream schema changes renaming the discriminator field; constructing the dict from unvalidated user JSON.","solutions":["Set type to exactly 'document_url' (with a 'document_url' key) or 'image_url' (with an 'image_url' key).","Validate/whitelist the type field when building the dict from user input.","Ensure the discriminator key 'type' is present at the top level of the dict."],"exampleFix":"# before\ndoc = {\"type\": \"pdf\", \"url\": \"https://x.com/f.pdf\"}\n\n# after\ndoc = {\"type\": \"document_url\", \"document_url\": \"https://x.com/f.pdf\"}","handlingStrategy":"validation","validationCode":"def make_document(url: str, *, image: bool = False) -> dict:\n    t = \"image_url\" if image else \"document_url\"\n    if t not in (\"document_url\", \"image_url\"):\n        raise ValueError(\"bad type\")\n    return {\"type\": t, t: url}","typeGuard":"def has_valid_doc_type(doc: object) -> bool:\n    return isinstance(doc, dict) and doc.get(\"type\") in (\"document_url\", \"image_url\")","tryCatchPattern":null,"preventionTips":["Whitelist the type field to exactly 'document_url' or 'image_url'.","Construct the dict via a helper so the discriminator is never hand-typed."],"tags":["azure","document-intelligence","ocr","validation","request-format"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}