BerriAI/litellm · error · ValueError
Invalid document type: {doc_type}. Must be 'document_url' or
Error message
Invalid document type: {doc_type}. Must be 'document_url' or 'image_url' What it means
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.
Source
Thrown at litellm/llms/azure_ai/ocr/document_intelligence/transformation.py:370
Returns:
OCRRequestData with JSON data
"""
verbose_logger.debug("Azure Document Intelligence transform_ocr_request - model: %s", model)
if not isinstance(document, dict):
raise ValueError(f"Expected document dict, got {type(document)}")
# Extract document URL from Mistral format
doc_type: Final = document.get("type")
document_url = None
if doc_type == "document_url":
document_url = document.get("document_url", "")
elif doc_type == "image_url":
document_url = document.get("image_url", "")
else:
raise ValueError(f"Invalid document type: {doc_type}. Must be 'document_url' or 'image_url'")
if not document_url:
raise ValueError("Document URL is required")
# Build Azure DI request
data: Final[dict[str, Any]] = {}
# Check if it's a data URI (base64)
if document_url.startswith("data:"):
# Extract base64 content
base64_content: Final = self._extract_base64_from_data_uri(document_url)
data["base64Source"] = base64_content
verbose_logger.debug("Using base64Source for Azure Document Intelligence")
else:
# Regular URL
data["urlSource"] = document_url
verbose_logger.debug("Using urlSource for Azure Document Intelligence")
View on GitHub (pinned to 6c2dcb801b)
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.
Example fix
# before
doc = {"type": "pdf", "url": "https://x.com/f.pdf"}
# after
doc = {"type": "document_url", "document_url": "https://x.com/f.pdf"} Defensive patterns
Strategy: validation
Validate before calling
def make_document(url: str, *, image: bool = False) -> dict:
t = "image_url" if image else "document_url"
if t not in ("document_url", "image_url"):
raise ValueError("bad type")
return {"type": t, t: url} Type guard
def has_valid_doc_type(doc: object) -> bool:
return isinstance(doc, dict) and doc.get("type") in ("document_url", "image_url") Prevention
- Whitelist the type field to exactly 'document_url' or 'image_url'.
- Construct the dict via a helper so the discriminator is never hand-typed.
When it happens
Trigger: Calling azure_ai doc-intelligence OCR with document={'type': 'file', ...}, {'type': 'pdf', ...}, or a dict missing the 'type' key entirely (doc_type becomes None).
Common situations: Guessing type names ('url', 'file_url', 'document'); typos; upstream schema changes renaming the discriminator field; constructing the dict from unvalidated user JSON.
Related errors
- Expected document dict, got {type(document)}
- Document URL is required
- Invalid `pages` string for Azure Document Intelligence: {pag
- `pages` integers must be >= 0 (Mistral 0-based indices)
- Invalid `pages` list for Azure Document Intelligence: {pages
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/eb9ab6405eb6b0d3.
Report an issue: GitHub.