From 3188f93be0adf63349d708e9de97063ad97b6d13 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Mon, 22 Jun 2026 18:49:03 -0700 Subject: [PATCH] ocr: lazily import rust bridge inside ocr() to break the import cycle the CodeQL autofix mangled --- litellm/ocr/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/litellm/ocr/main.py b/litellm/ocr/main.py index 96b272d96bd..55c74952249 100644 --- a/litellm/ocr/main.py +++ b/litellm/ocr/main.py @@ -39,8 +39,6 @@ async def aocr( extra_headers: Optional[Dict[str, Any]] = None, **kwargs, ) -> OCRResponse: - from litellm.ocr.rust_bridge import rust_ocr, rust_ocr_enabled - """ Async OCR function. @@ -264,6 +262,10 @@ def ocr( api_base = dynamic_api_base # Optional Rust path: hand the whole Mistral OCR call to the Rust bridge. + # Imported lazily to avoid a module-level import cycle (CodeQL flags the + # litellm.ocr.main -> litellm.ocr.rust_bridge edge during package init). + from litellm.ocr.rust_bridge import rust_ocr, rust_ocr_enabled + if custom_llm_provider == "mistral" and rust_ocr_enabled(): return rust_ocr(model, document, api_key, api_base, kwargs)