litellm/litellm-rust/crates/python-bridge
devin-ai-integration[bot] 6661462d5a
fix(ocr-errors): preserve public error and timeout contracts (#33605)
* fix(ocr-errors): preserve public error and timeout contracts

Classify reqwest timeouts as a typed CoreError::Timeout and add
CoreError::public_status_code() as the single exhaustive mapping from a
typed core error to its public HTTP status. The Python bridge raises a
typed RustOcrError carrying that status instead of a generic
RuntimeError, and litellm.ocr()/aocr() translate it into the matching
public exception so AuthenticationError/401, NotFoundError/404,
BadRequestError/4xx, InternalServerError/5xx and Timeout are preserved
end to end instead of collapsing to APIConnectionError/500.

Reject empty or whitespace-only 200 bodies so they fail loudly rather
than becoming an empty OCR success; invalid JSON already fails. Upstream
error bodies stay bounded and sanitized.

Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>

* fix(ocr-errors): map invalid OCR input to BadRequestError

Invalid caller input (bad document type, non-dict document, unusable
file input) was raised as a plain ValueError inside ocr()/aocr() and
collapsed to APIConnectionError/500 through the generic handler. Route
every OCR failure through one _map_ocr_exception host mapping: typed
RustOcrError keeps its status-based public exception, a plain ValueError
becomes BadRequestError/400, and a pydantic ValidationError (malformed
response, not client input) stays on the generic path.

Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>

* refactor(ocr-errors): data-minimize public errors and preserve status-specific exceptions

Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>

* refactor(ocr-errors): preserve exact unknown status and privatize input error

Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>

* refactor(ocr-errors): exhaustive match mapper and typed error tests

Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>

* fix(ocr-errors): sanitize InvalidRequest public message

Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>

* refactor(ocr-errors): raise typed public union and drop NotFound provider miss

Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>

* fix(ocr-errors): map malformed provider responses to sanitized 500 and hide input-error detail

Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>
2026-07-16 19:49:26 -07:00
..
src fix(ocr-errors): preserve public error and timeout contracts (#33605) 2026-07-16 19:49:26 -07:00
AGENTS.md refactor(litellm-rust): dissolve providers into core + ai-gateway (strict 3-crate layers) (#31218) 2026-06-24 12:22:43 -07:00
build.rs feat: package Rust OCR bridge in LiteLLM wheel (#31267) 2026-06-25 12:32:55 -07:00
Cargo.toml feat: port OCR providers to Rust gateway 2026-06-25 13:01:33 -07:00
CLAUDE.md feat: add LiteLLM Rust workspace with Mistral OCR bridge (#31033) 2026-06-23 13:16:47 -07:00