{"record":{"id":"00d50d4b6d72b556","repo":"BerriAI/litellm","slug":"document-must-be-a-dict-with-type-and-url-file-f","errorCode":null,"errorMessage":"document must be a dict with 'type' and URL/file field, got {type(document)}","messagePattern":"document must be a dict with 'type' and URL/file field, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/ocr/main.py","lineNumber":79,"sourceCode":"    \"vertex_ai\",\n}\n\n\ndef _prepare_ocr_request(\n    model: str,\n    document: Mapping[str, object],\n    api_key: str | None,\n    api_base: str | None,\n    timeout: float | httpx.Timeout | None,\n    custom_llm_provider: str | None,\n    extra_headers: dict[str, object] | None,\n    kwargs: dict[str, object],\n) -> _PreparedOCRRequest:\n    litellm_logging_obj: Final = cast(LiteLLMLoggingObj, kwargs.pop(\"litellm_logging_obj\"))\n    litellm_call_id: Final = cast(str | None, kwargs.get(\"litellm_call_id\", None))\n\n    if not isinstance(document, dict):\n        raise ValueError(f\"document must be a dict with 'type' and URL/file field, got {type(document)}\")\n\n    doc_type = document.get(\"type\")\n\n    if doc_type == \"file\":\n        document = convert_file_document_to_url_document(document)\n        doc_type = document.get(\"type\")\n\n    if doc_type not in [\"document_url\", \"image_url\"]:\n        raise ValueError(f\"Invalid document type: {doc_type}. Must be 'document_url', 'image_url', or 'file'\")\n\n    caller_supplied_api_base: Final = api_base is not None\n\n    (\n        model,\n        custom_llm_provider,\n        dynamic_api_key,\n        dynamic_api_base,\n    ) = litellm.get_llm_provider(","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/ocr/main.py#L61-L97","documentation":"Type guard at the top of _prepare_ocr_request: the document argument is not a dict (Mapping alone is not enough downstream), so its 'type' and URL/file payload cannot be read. The received type is echoed in the message.","triggerScenarios":"Thrown at litellm/ocr/main.py:79 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass the document as a dict with 'type' plus the corresponding URL or file field, e.g. {'type': 'image_url', 'image_url': {...}}.","Convert other document representations into this dict structure before calling the OCR API."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}