Merge pull request #38765 from BerriAI/litellm_ocr_sdk_parity_tests

test(harness): add OCR parity with migration strategy runners
This commit is contained in:
yujonglee 2026-09-03 10:16:35 -07:00 committed by GitHub
parent bd9de39349
commit 2c30fe16b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
134 changed files with 11383 additions and 1353 deletions

View file

@ -4,6 +4,11 @@ description: >-
by a job nor listed here, so every entry below is a decision on the record.
test_paths:
- reason: >-
The Rust/Python parity harness is run manually through its local CLI. Recorded replay,
fixture generation, and harness checks are intentionally outside pull request CI
paths:
- tests/rust-python-harness
- reason: >-
What is left of the caching suite in tests/local_testing that runs nowhere. Every job that
globs that directory either deselects it (local_testing_part1 and part2 carry `-k "... and

View file

@ -27,7 +27,7 @@ rand = "0.8"
reqwest = { version = "0.12", default-features = false, features = ["blocking", "json", "rustls-tls", "http2", "stream"] }
rstest = "0.26.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_json = { version = "1.0", features = ["float_roundtrip"] }
sha2 = "0.10"
subtle = "2"
thiserror = "2.0"

View file

@ -14,7 +14,7 @@ const AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT_ENV: &str = "AZURE_DOCUMENT_INTELLIGE
const AZURE_DOCUMENT_INTELLIGENCE_API_VERSION: &str = "2024-11-30";
const AZURE_DOCUMENT_INTELLIGENCE_DEFAULT_DPI: i64 = 96;
const AZURE_DOCUMENT_INTELLIGENCE_SUPPORTED_OCR_PARAMS: &[&str] = &["pages"];
const AZURE_DOCUMENT_INTELLIGENCE_SUPPORTED_OCR_PARAMS: &[&str] = &["pages", "features"];
pub struct AzureAiOcrConfig;
pub struct AzureDocumentIntelligenceOcrConfig;
@ -192,6 +192,46 @@ fn normalize_pages_param(pages: &Value) -> Result<Option<String>, Error> {
}
}
fn feature_token_is_valid(token: &str) -> bool {
let Some((first, rest)) = token.as_bytes().split_first() else {
return false;
};
first.is_ascii_alphabetic() && rest.iter().all(u8::is_ascii_alphanumeric)
}
fn invalid_features_error(features: &Value) -> Error {
Error::InvalidRequest(format!(
"Invalid `features` for Azure Document Intelligence: {features:?}. Expected a list of feature names or a comma-separated string like 'keyValuePairs' or 'keyValuePairs,languages'."
))
}
fn normalize_features_param(features: &Value) -> Result<Option<String>, Error> {
let normalized = match features {
Value::String(value) => value
.split(',')
.map(str::trim)
.collect::<Vec<_>>()
.join(","),
Value::Array(values) if values.is_empty() => return Ok(None),
Value::Array(values) => values
.iter()
.map(Value::as_str)
.collect::<Option<Vec<_>>>()
.ok_or_else(|| invalid_features_error(features))?
.into_iter()
.map(str::trim)
.collect::<Vec<_>>()
.join(","),
_ => return Err(invalid_features_error(features)),
};
if normalized.split(',').all(feature_token_is_valid) {
Ok(Some(normalized))
} else {
Err(invalid_features_error(features))
}
}
pub fn complete_document_intelligence_url(
api_base: Option<&str>,
model: &str,
@ -213,6 +253,13 @@ pub fn complete_document_intelligence_url(
url.push_str(&normalized);
}
if let Some(features) = optional_params.get("features")
&& let Some(normalized) = normalize_features_param(features)?
{
url.push_str("&features=");
url.push_str(&normalized);
}
Ok(url)
}
@ -475,6 +522,103 @@ mod tests {
);
}
#[test]
fn document_intelligence_url_normalizes_features() {
let params = serde_json::Map::from_iter([(
"features".to_string(),
json!("keyValuePairs, languages"),
)]);
let url = complete_document_intelligence_url(
Some("https://example.cognitiveservices.azure.com"),
"prebuilt-layout",
&params,
&|_| None,
)
.expect("url builds");
assert_eq!(
url,
"https://example.cognitiveservices.azure.com/documentintelligence/documentModels/prebuilt-layout:analyze?api-version=2024-11-30&features=keyValuePairs,languages"
);
}
#[test]
fn document_intelligence_url_combines_pages_and_feature_list() {
let params = serde_json::Map::from_iter([
("pages".to_string(), json!([0, 1, 2])),
(
"features".to_string(),
json!([" keyValuePairs ", "languages"]),
),
]);
let url = complete_document_intelligence_url(
Some("https://example.cognitiveservices.azure.com"),
"prebuilt-layout",
&params,
&|_| None,
)
.expect("url builds");
assert_eq!(
url,
"https://example.cognitiveservices.azure.com/documentintelligence/documentModels/prebuilt-layout:analyze?api-version=2024-11-30&pages=1,2,3&features=keyValuePairs,languages"
);
}
#[test]
fn document_intelligence_url_omits_empty_feature_list() {
let params = serde_json::Map::from_iter([("features".to_string(), json!([]))]);
let url = complete_document_intelligence_url(
Some("https://example.cognitiveservices.azure.com"),
"prebuilt-layout",
&params,
&|_| None,
)
.expect("url builds");
assert_eq!(
url,
"https://example.cognitiveservices.azure.com/documentintelligence/documentModels/prebuilt-layout:analyze?api-version=2024-11-30"
);
}
#[test]
fn document_intelligence_url_rejects_invalid_features() {
for features in [
json!("keyValuePairs&pages=9"),
json!(""),
json!(["keyValuePairs", 1]),
json!({"feature": "keyValuePairs"}),
] {
let params = serde_json::Map::from_iter([("features".to_string(), features.clone())]);
let error = complete_document_intelligence_url(
Some("https://example.cognitiveservices.azure.com"),
"prebuilt-layout",
&params,
&|_| None,
)
.expect_err("invalid features must fail");
assert!(
matches!(error, Error::InvalidRequest(message) if message.contains("Invalid `features`")),
"features={features:?}"
);
}
}
#[test]
fn document_intelligence_maps_features() {
let params = Map::from_iter([
("features".to_string(), json!(["keyValuePairs"])),
("unsupported".to_string(), json!(true)),
]);
assert_eq!(
AZURE_DOCUMENT_INTELLIGENCE_OCR_CONFIG.map_ocr_params(&params),
Map::from_iter([("features".to_string(), json!(["keyValuePairs"]))])
);
}
#[test]
fn document_intelligence_request_uses_base64_source_for_data_uri() {
let body = AZURE_DOCUMENT_INTELLIGENCE_OCR_CONFIG

View file

@ -59,3 +59,41 @@ pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
module.add("RustBridgeDeclined", py.get_type::<RustBridgeDeclined>())?;
module.add("RustUpstreamError", py.get_type::<RustUpstreamError>())
}
pub(crate) fn ocr_error_to_pyerr(err: Error) -> PyErr {
match err {
Error::MissingField("document_url" | "image_url") => {
PyValueError::new_err("Document URL is required")
}
Error::Http { status, body } => RustUpstreamError::new_err((status, body)),
other => core_error_to_pyerr(other),
}
}
#[cfg(test)]
mod ocr_error_tests {
use super::*;
#[test]
fn ocr_errors_preserve_python_validation_and_provider_details() {
Python::initialize();
Python::attach(|py| {
for field in ["document_url", "image_url"] {
let mapped = ocr_error_to_pyerr(Error::MissingField(field));
assert!(mapped.is_instance_of::<PyValueError>(py));
assert_eq!(mapped.value(py).to_string(), "Document URL is required");
}
let mapped = ocr_error_to_pyerr(Error::Http {
status: 429,
body: r#"{"message":"rate limited"}"#.to_string(),
});
assert!(mapped.is_instance_of::<RustUpstreamError>(py));
let args: (u16, String) = mapped
.value(py)
.getattr("args")
.and_then(|args| args.extract())
.expect("OCR failures retain status and unprefixed provider message");
assert_eq!(args, (429, r#"{"message":"rate limited"}"#.to_string()));
});
}
}

View file

@ -5,7 +5,7 @@ use litellm_ai_gateway::io::ocr::{OcrRequest, ocr as run_ocr};
use pyo3::prelude::*;
use serde_json::Value;
use crate::errors::core_error_to_pyerr;
use crate::errors::ocr_error_to_pyerr;
use crate::marshal::{RouteOptions, RouteOptionsInputs, object_or_empty};
fn prepare_ocr(
@ -69,5 +69,5 @@ bridge_route! {
timeout_seconds: Option<f64>,
},
prepare = prepare_ocr,
errors = core_error_to_pyerr,
errors = ocr_error_to_pyerr,
}

View file

@ -174,6 +174,8 @@ litellm-proxy = "litellm.proxy.client.cli:cli"
[dependency-groups]
dev = [
"diff-cover==9.7.2",
"hypothesis==6.165.10",
"reportlab==5.0.1",
"basedpyright==1.39.7",
"keyring==25.7.0",
"pytest==9.0.3",

View file

@ -172,6 +172,7 @@ pylint: >=3.3.9 # GPLv2 license
langchain-mcp-adapters: >=0.2.1 # MIT License
langgraph: >=1.0.10 # MIT License
langgraph-prebuilt: >=1.0.8 # MIT License - https://github.com/langchain-ai/langgraph/blob/main/LICENSE
hypothesis: >=6.165.10 # MPL 2.0 license
pytest-rerunfailures: >=15.1 # MPL 2.0 license
pytest-recording: >=0.13.4 # MIT license
expression: >=5.6.0 # MIT License - https://github.com/cognitedata/Expression/blob/main/LICENSE

View file

@ -1,148 +1,105 @@
# Rust ↔ Python SDK parity harness
# Rust/Python migration harness
This folder is the operator-facing harness for the Rust migration test plan. It runs pytest normally, listens to test events in-process, and redraws a live matrix grouped by testing strategy and SDK-level function.
This local harness follows [the agreed structure](AGENTS.md). The root command selects strategies and combines their reports. Each strategy has an independent entry point
The matrix always has these SDK columns:
- `ocr / aocr`
- `messages / amessages`
- `responses / aresponses`
- `count_tokens`
- `chat_completions / acompletion`
- `transcription / atranscription`
The harness has four deliberately broad test-strategy folders:
| Strategy | Folder |
| --- | --- |
| Public SDK parity over generated and recorded inputs | [`e2e_fuzz_tests/`](e2e_fuzz_tests/) |
| Focused tests of Rust-owned behavior | [`unit_tests_rust/`](unit_tests_rust/) |
| Isolated transform and Python-to-Rust helper coverage | [`validate_sub_methods/`](validate_sub_methods/) |
| Already-existing live-API SDK tests | [`existing_e2e_test_sdk/`](existing_e2e_test_sdk/) |
## Run it
From the repository root:
```bash
poetry run python -m tests.rust-python-harness
```text
strategies/
e2e_parity/runner.py
sdk/ocr/fixtures/
sdk/messages/
sdk/chat_completions/
sdk/responses/
gateway/
existing_e2e_test_sdk/runner.py
trace_parity/runner.py
sdk/
gateway/
unit_tests/
runner.py
mapping_validator.py
python_runner.py
rust_runner.py
shared/
parity/
tracing/
reporting/
```
The default runs every configured test once and updates all matching cells in real time. Narrow a run by strategy, SDK function, or both:
## Run locally
```bash
poetry run python -m tests.rust-python-harness --strategy e2e_fuzz_tests
poetry run python -m tests.rust-python-harness --function messages
poetry run python -m tests.rust-python-harness --strategy validate_sub_methods --function ocr
uv run python -m tests.rust-python-harness --list
uv run python -m tests.rust-python-harness --function ocr --plain
uv run python -m tests.rust-python-harness --strategy e2e_parity --surface sdk --function ocr --plain
uv run python -m tests.rust-python-harness.strategies.e2e_parity.runner --function ocr --plain
uv run python -m tests.rust-python-harness.strategies.trace_parity.runner --plain
uv run python -m tests.rust-python-harness.strategies.unit_tests.runner --plain
uv run python -m tests.rust-python-harness.strategies.existing_e2e_test_sdk.runner --function transcription --plain
```
For a guided run, use the interactive picker. It asks which strategy rows and SDK
function columns to include, then hands the terminal to the live dashboard. It never
captures keys while tests are running, so Ctrl-C and pytest debugging remain safe.
Use `--interactive` for strategy and function selection, `--pytest-arg=-x` to stop pytest on its first failure, and `--coverage` to write Python coverage under `target/rust-python-harness/`. The harness enables pytest namespace-package discovery only for its own invocations
```bash
poetry run python -m tests.rust-python-harness --interactive
```
This harness has no CI execution. A configured test that fails or disappears makes the command fail. An unconfigured strategy cell remains planned and contributes no passing evidence. Interruptions and collection errors stop execution; ordinary test failures remain in the combined report while later strategies run
Useful operator options:
## Strategy responsibilities
```bash
# Inspect coverage and pytest selectors without running anything.
poetry run python -m tests.rust-python-harness --list
E2E parity compares SDK objects, exceptions, callbacks, streams, and provider requests. Gateway tests compare HTTP responses. Both surfaces use the same strategy runner and keep execution details and fixtures in their own folders. OCR has recorded sync/async SDK coverage; the existing Messages and Responses bridge checks remain partial
# Stable line-oriented output for CI logs or redirected output.
poetry run python -m tests.rust-python-harness --plain
Trace parity compares operation names through an explicit Python/Rust mapping, call counts, and required completion-before-start ordering with `shared/tracing/compare.py`. Surface tests supply captured operation intervals. No production trace instrumentation or trace case is configured yet
# Measure Python reference lines exercised by this parity run and build an HTML heatmap.
poetry run python -m tests.rust-python-harness --coverage
Unit testing combines test mapping validation, separate Python processes with Rust disabled and enabled, backend verification, result comparison, and native Cargo tests. Native tests stay beside their Rust implementation. Existing Python tests stay at their original paths. No complete Python/native unit mapping is configured yet, so these cells remain planned
# Forward pytest options. Use the equals form when the value begins with a dash.
poetry run python -m tests.rust-python-harness --pytest-arg=-x
```
The existing E2E SDK strategy retains the live provider tests configured upstream. It runs OCR, Chat Completions, and Transcription checks from their existing paths and reports them separately from parity tests. These tests require provider credentials
The process returns pytest's exit code. A configured selector that collects no test is also a failure. A planned cell has no selector yet and does not fail the run.
## Configure cases
The dashboard adapts to narrow terminals, shows elapsed time and unique-test progress,
and prints the three slowest tests when the run ends. Each failure includes a focused
`poetry run pytest ... -q` command. Redirected output and CI automatically use the
line-oriented plain renderer; `--plain` lets you opt into it locally.
The final screen includes a confidence score for every SDK section. It is the direct
ratio of required strategy rows with passing evidence, such as `1/3 = 33%`; High means
all required strategies passed, Medium means some passed, and Low means none passed.
This behavioral score is intentionally shown separately from Python and Rust LOC.
Coverage reports are written outside the three strategy folders at
`target/rust-python-harness/`. Open `python-html/index.html` to inspect executed and
missing Python lines; `python.json` and `python.xml` are available for automation.
Coverage is finalized after pytest exits, because worker processes must flush their
data first.
## Port coverage and confidence
Treat these as separate signals instead of one ambiguous coverage percentage:
| Signal | Tool | What it proves |
| --- | --- | --- |
| Python reference LOC | `coverage.py` / `pytest-cov` via `--coverage` | The mapped Python behavior ran |
| Rust port LOC | `cargo-llvm-cov` | The mapped Rust implementation ran |
| Parity contracts | This harness matrix | Python and Rust had the same observable behavior |
`validate_sub_methods/` owns the future source-section inventory that maps a stable
Python qualified symbol to its Rust symbol. That inventory is the denominator for
per-function rollups; raw coverage for the entire LiteLLM repository would obscure
the port's real gaps. `unit_tests_rust/` owns direct `cargo-llvm-cov` runs, while
`e2e_fuzz_tests/` owns behavioral parity and fuzz-case counts. Keep Python, Rust, and
parity percentages visible side by side and label section confidence High only when
the mapped implementation exists, every required strategy passes, and both sides meet
their LOC thresholds. Generated Rust LCOV/HTML and the combined index also belong in
`target/rust-python-harness/`, not in a fourth strategy folder.
## Read the matrix
| Mark | Meaning |
| --- | --- |
| `✓` | All collected tests passed |
| `✗` | At least one test failed |
| `!` | Test setup or teardown failed |
| `↷` | All collected tests skipped |
| `?` | A configured selector did not collect a test |
| `—` | Strategy is planned but has no test yet |
| `n/a` | Strategy does not apply to this SDK function |
| `◐` | The configured tests cover only part of the TDD's parity contract |
The initial end-to-end entries deliberately show `◐`: the repository has Rust bridge tests for OCR, Messages, and Responses websocket plumbing, but those are not yet frozen-Python-oracle comparisons. The remaining TDD cells stay visible as planned work instead of disappearing from a green summary.
## Attach parity tests
Each of the four folders contains a concise `README.md` and a `strategy.json`. Add a pytest file or node ID to the appropriate SDK function's `selectors` list:
Each strategy has a `strategy.json`. Its `functions` object defines SDK cases for OCR, Messages, Responses, Count Tokens, Chat Completions, and Transcription. E2E and trace manifests also accept a `gateway` object keyed by API name. A case has `coverage`, `selectors`, and an optional `note`
```json
{
"coverage": "complete",
"selectors": [
"tests/rust-python-harness/validate_sub_methods/test_messages.py"
]
"coverage": "partial",
"selectors": ["tests/rust-python-harness/strategies/e2e_parity/sdk/ocr/test_sdk_parity.py"]
}
```
Selectors use the same syntax as pytest. A file selector aggregates every test in the file; a node selector can target one test or parametrized family; a selector ending in `/` aggregates every test in that folder, recursively. The runner deduplicates selectors, so one test may intentionally prove more than one cell without executing twice.
Selectors use pytest file or node syntax. A selector ending in `/` includes tests recursively from that directory
Use these coverage values:
Use `planned` with no selectors until an executable contract exists, `partial` for incomplete coverage, `complete` for the full contract, and `not_applicable` when a strategy does not apply. The dashboard shows passing evidence separately from coverage completeness and LOC coverage
- `complete`: implements the full strategy contract for that SDK function.
- `partial`: useful coverage exists, but the TDD contract is not fully proven.
- `planned`: no runnable parity test exists yet.
- `not_applicable`: the strategy cannot apply, such as streaming for OCR.
Unit cases use `unit_suite` instead of `selectors`, pointing to a repository-relative JSON file with this shape:
Keep comparison mechanics in shared harness modules and provider/function facts in the owning strategy folder. A Python/Rust mismatch is a test failure; do not normalize away observable return types, exception classes, private response fields, chunk ordering, or callback payload differences merely to make a cell green.
```json
{
"python_selectors": ["tests/test_api.py::test_decode"],
"cargo_manifest": "litellm-rust/Cargo.toml",
"cargo_package": "litellm-core",
"cargo_filter": "ocr::",
"backend": {
"environment_variable": "LITELLM_USE_RUST_OCR",
"probe": "tests.rust-python-harness.strategies.unit_tests.python_runner:ocr_backend"
},
"mappings": [{"python": "tests/test_api.py::test_decode", "rust": "ocr::test_decode"}]
}
```
## Architecture
Names match automatically when the collected Python and Rust test names agree. Explicit `mappings` handle different names, class names, and parametrized cases. Missing or ambiguous counterparts fail validation in either direction. The Cargo filter must select the same behavior as the Python selectors
- `catalog.py` validates and loads every strategy manifest.
- `models.py` owns typed strategy, case, coverage, and run-state models.
- `runner.py` maps live pytest events back to one or more matrix cells.
- `ui.py` renders the interactive Rich dashboard and a dependency-free plain fallback.
- `cli.py` handles filtering and preserves pytest exit semantics.
The backend probe returns `python` or `rust` and runs at startup and before every test call, after fixtures have run. The OCR probe verifies the dispatch flag and native extension availability. Surface tests must also assert that calls reach their intended implementation to catch per-call fallback. Python outcomes must agree, and failed runs remain failures even if both backends fail identically
The harness is driven from Python, matching the SDK surface and existing test tooling. Rust remains responsible for the implementation under comparison; the harness does not move provider semantics into the PyO3 bridge.
## OCR fixtures
Fixtures, provider configuration, input strategies, and recording commands live in [the OCR package](strategies/e2e_parity/sdk/ocr/fixtures/README.md). Record with provider credentials:
```bash
uv run python -m tests.rust-python-harness.strategies.e2e_parity.sdk.ocr.fixtures.record --examples 1000
```
`LITELLM_OCR_FIXTURE_DIR` and `--fixture-dir` override the default directory. Shared recording, replay, comparison, streaming, and cassette persistence live in `shared/parity/`
Run the harness's own checks locally:
```bash
uv run pytest -o consider_namespace_packages=true tests/rust-python-harness/shared tests/rust-python-harness/strategies/unit_tests tests/test_rust_python_harness.py -q
```
Existing OCR parity gaps remain visible: invalid-model provider errors differ, Reducto lacks a native contract, and the expanded Azure corpus exposes duplicate Content-Type headers. Moving the harness does not change provider responses or weaken assertions

View file

@ -2,92 +2,74 @@ from __future__ import annotations
import json
from pathlib import Path
from typing import Any
from typing import Final
from .models import Coverage, HarnessCase, SDK_FUNCTIONS, Strategy
from pydantic import BaseModel, ConfigDict, ValidationError
STRATEGIES_ROOT = Path(__file__).parent
from .shared.reporting.models import Coverage, HarnessCase, SDK_FUNCTIONS, Strategy
STRATEGIES_ROOT: Final = Path(__file__).parent / "strategies"
def _require_string(value: Any, field: str, source: Path) -> str:
if not isinstance(value, str) or not value.strip():
raise ValueError(f"{source}: {field} must be a non-empty string")
return value
class CaseSpec(BaseModel):
model_config = ConfigDict(frozen=True, extra="forbid")
coverage: Coverage
selectors: tuple[str, ...] = ()
note: str = ""
unit_suite: str | None = None
class StrategySpec(BaseModel):
model_config = ConfigDict(frozen=True, extra="forbid")
order: int
id: str
label: str
description: str
functions: dict[str, CaseSpec]
gateway: dict[str, CaseSpec] = {}
def _load_strategy(source: Path) -> Strategy:
with source.open(encoding="utf-8") as stream:
data = json.load(stream)
strategy_id = _require_string(data.get("id"), "id", source)
label = _require_string(data.get("label"), "label", source)
description = _require_string(data.get("description"), "description", source)
order = data.get("order")
if not isinstance(order, int):
raise ValueError(f"{source}: order must be an integer")
function_data = data.get("functions")
if not isinstance(function_data, dict):
raise ValueError(f"{source}: functions must be an object")
missing = set(SDK_FUNCTIONS) - set(function_data)
extra = set(function_data) - set(SDK_FUNCTIONS)
if missing or extra:
raise ValueError(
f"{source}: functions must exactly match {SDK_FUNCTIONS}; missing={missing}, extra={extra}"
data: Final = StrategySpec.model_validate_json(source.read_text(encoding="utf-8"))
if set(data.functions) != set(SDK_FUNCTIONS):
raise ValueError(f"{source}: functions must exactly match {SDK_FUNCTIONS}")
cases: Final = tuple(
HarnessCase(
strategy_id=data.id,
strategy_label=data.label,
sdk_function=name,
coverage=case.coverage,
selectors=case.selectors,
note=case.note,
surface=surface,
unit_suite=case.unit_suite,
)
cases: list[HarnessCase] = []
for sdk_function in SDK_FUNCTIONS:
case_data = function_data[sdk_function]
if not isinstance(case_data, dict):
raise ValueError(f"{source}: functions.{sdk_function} must be an object")
try:
coverage = Coverage(case_data.get("coverage"))
except ValueError as exc:
raise ValueError(f"{source}: invalid coverage for {sdk_function}") from exc
selectors = case_data.get("selectors", [])
if not isinstance(selectors, list) or not all(
isinstance(item, str) and item for item in selectors
):
raise ValueError(
f"{source}: selectors for {sdk_function} must be a list of strings"
)
if coverage is Coverage.NOT_APPLICABLE and selectors:
raise ValueError(
f"{source}: not_applicable case {sdk_function} cannot have selectors"
)
cases.append(
HarnessCase(
strategy_id=strategy_id,
strategy_label=label,
sdk_function=sdk_function,
coverage=coverage,
selectors=tuple(selectors),
note=str(case_data.get("note", "")),
)
)
return Strategy(
order=order,
id=strategy_id,
label=label,
description=description,
directory=source.parent,
cases=tuple(cases),
for surface, functions in (("sdk", data.functions), ("gateway", data.gateway))
for name in (SDK_FUNCTIONS if surface == "sdk" else functions)
for case in (functions[name],)
)
for case in cases:
if case.coverage in {Coverage.PLANNED, Coverage.NOT_APPLICABLE} and (case.selectors or case.unit_suite):
raise ValueError(f"{source}: {case.coverage.value} case {case.key} cannot configure tests")
if any(not selector.strip() for selector in case.selectors):
raise ValueError(f"{source}: empty selector in {case.key}")
if data.id == "unit_tests" and case.selectors:
raise ValueError(f"{source}: unit_tests must configure unit_suite instead of pytest selectors")
if data.id != "unit_tests" and case.unit_suite:
raise ValueError(f"{source}: unit_suite is only valid for unit_tests")
return Strategy(data.order, data.id, data.label, data.description, source.parent, cases)
def load_catalog(root: Path = STRATEGIES_ROOT) -> tuple[Strategy, ...]:
sources = sorted(root.glob("*/strategy.json"))
sources: Final = tuple(sorted(root.glob("*/strategy.json")))
if not sources:
raise ValueError(f"No strategy manifests found below {root}")
strategies = tuple(
sorted(
(_load_strategy(source) for source in sources),
key=lambda strategy: strategy.order,
)
)
ids = [strategy.id for strategy in strategies]
if len(ids) != len(set(ids)):
try:
strategies: Final = tuple(sorted((_load_strategy(source) for source in sources), key=lambda item: item.order))
except (ValidationError, json.JSONDecodeError) as error:
raise ValueError(str(error)) from error
if len({strategy.id for strategy in strategies}) != len(strategies):
raise ValueError(f"Duplicate strategy id in {root}")
return strategies

View file

@ -6,10 +6,14 @@ from collections.abc import Sequence
from pathlib import Path
from .catalog import load_catalog
from .models import SDK_FUNCTIONS, HarnessCase, Strategy
from .runner import run_pytest
from .ui import make_dashboard
from .shared.reporting.models import SDK_FUNCTIONS, HarnessCase, Strategy
from .shared.reporting.orchestration import StrategyRunner, run_strategies
from .shared.reporting.ui import make_dashboard
from .strategies.e2e_parity.runner import run as run_e2e
from .strategies.existing_e2e_test_sdk.runner import run as run_existing
from .strategies.trace_parity.runner import run as run_trace
from .strategies.unit_tests.mapping_validator import FunctionReport, build_function_report
from .strategies.unit_tests.runner import run as run_units
REPO_ROOT = Path(__file__).resolve().parents[2]
COVERAGE_ROOT = REPO_ROOT / "target" / "rust-python-harness"
@ -44,6 +48,7 @@ def _parser() -> argparse.ArgumentParser:
choices=SDK_FUNCTIONS,
help="run only this SDK function",
)
parser.add_argument("--surface", choices=("sdk", "gateway"), help="run only this API surface")
parser.add_argument(
"--validate-ledger",
action="store_true",
@ -135,9 +140,9 @@ def _print_catalog(strategies: Sequence[Strategy]) -> None:
print(f"{strategy.id:20} {strategy.label}")
for case in strategy.cases:
selectors = (
", ".join(case.selectors) if case.selectors else "no test configured"
", ".join(case.selectors) if case.selectors else case.unit_suite or "no test configured"
)
print(f" {case.sdk_function:12} {case.coverage.value:14} {selectors}")
print(f" {case.surface}/{case.sdk_function:12} {case.coverage.value:14} {selectors}")
def _print_function_report(report: FunctionReport) -> None:
@ -172,7 +177,21 @@ def _validate_ledger(sdk_functions: set[str]) -> int:
return 0 if all(report.is_clean for report in reports) else 1
def main(argv: Sequence[str] | None = None) -> int:
def _resolve_runner(strategy_id: str) -> StrategyRunner:
match strategy_id:
case "e2e_parity":
return run_e2e
case "trace_parity":
return run_trace
case "unit_tests":
return run_units
case "existing_e2e_test_sdk":
return run_existing
case _:
raise ValueError(f"Unknown strategy: {strategy_id}")
def main(argv: Sequence[str] | None = None, *, strategy_id: str | None = None) -> int:
args = _parser().parse_args(argv)
if args.coverage and importlib.util.find_spec("pytest_cov") is None:
_parser().error(
@ -181,7 +200,8 @@ def main(argv: Sequence[str] | None = None) -> int:
)
if args.validate_ledger:
return _validate_ledger(set(args.sdk_functions))
strategies = load_catalog()
catalog = load_catalog()
strategies = tuple(strategy for strategy in catalog if strategy_id is None or strategy.id == strategy_id)
if args.list:
_print_catalog(strategies)
return 0
@ -194,7 +214,8 @@ def main(argv: Sequence[str] | None = None) -> int:
sdk_functions = sdk_functions or picked_functions
try:
cases = _select(strategies, strategy_ids, sdk_functions)
selected = _select(strategies, strategy_ids, sdk_functions)
cases = tuple(case for case in selected if args.surface is None or case.surface == args.surface)
except ValueError as exc:
_parser().error(str(exc))
selected_strategy_ids = {case.strategy_id for case in cases}
@ -210,11 +231,12 @@ def main(argv: Sequence[str] | None = None) -> int:
if args.coverage:
pytest_args.extend(_coverage_pytest_args())
with dashboard:
exit_code, run = run_pytest(
exit_code, run = run_strategies(
cases=cases,
repo_root=REPO_ROOT,
on_update=dashboard.update,
pytest_args=pytest_args,
resolve_runner=_resolve_runner,
)
dashboard.finish(run, exit_code)
if args.coverage and (COVERAGE_ROOT / "python.json").exists():

View file

@ -1,3 +0,0 @@
# End-to-end fuzz tests
Runs the same SDK call through the Python and Rust paths using generated inputs and recorded provider responses. It compares public results, streams, callbacks, and exceptions to catch behavior differences a unit test can miss.

View file

@ -1,14 +0,0 @@
{
"order": 10,
"id": "e2e_fuzz_tests",
"label": "End-to-end fuzz tests",
"description": "Compare observable Python and Rust SDK behavior over generated and recorded inputs.",
"functions": {
"ocr": {"coverage": "partial", "selectors": ["tests/test_litellm/ocr/test_rust_bridge.py"], "note": "Bridge coverage exists; frozen-oracle fuzz parity is still being added."},
"messages": {"coverage": "partial", "selectors": ["tests/test_litellm/anthropic_interface/test_rust_bridge_messages.py"], "note": "Bridge coverage exists; frozen-oracle fuzz parity is still being added."},
"responses": {"coverage": "partial", "selectors": ["tests/test_litellm/responses/test_rust_bridge_websocket.py"], "note": "Covers the websocket bridge; full responses parity is still being added."},
"count_tokens": {"coverage": "planned", "selectors": [], "note": "No Rust count_tokens parity test is present yet."},
"chat_completions": {"coverage": "partial", "selectors": ["tests/test_litellm/rust_bridge/test_chat_completions.py"], "note": "Bridge coverage exists; frozen-oracle fuzz parity is still being added."},
"transcription": {"coverage": "partial", "selectors": ["tests/test_litellm/test_audio_transcription_rust_bridge.py"], "note": "Bridge coverage exists; frozen-oracle fuzz parity is still being added."}
}
}

View file

@ -0,0 +1,91 @@
# Implementation parity testing through the SDK interface
> Given the same SDK call and identical provider behavior, do two implementations expose the same SDK contract?
## What the harness compares
- A fixture contains a LiteLLM SDK input and a recorded upstream provider response
- The same LiteLLM input is transformed by isolated baseline and candidate implementations
- The resulting provider requests must match in method, path, headers, and body, excluding runtime-specific HTTP metadata
- The recorded provider response is then replayed unchanged to both workers
- The harness compares the values returned through the Python SDK interface
- Non-streaming responses are compared directly, including their concrete return type and public model fields
- Streaming responses are consumed and compared chunk by chunk, including wrapper type, chunk type and order, termination, and public exception behavior
- Failed SDK calls are compared by exception class, stable message, status, code, model, provider, and parameter fields
- Traceback paths and line numbers are excluded because they are runtime-specific
- Route-specific comparators and chunk normalizers handle differences in each public SDK contract
## Process isolation
- SDK object and stream parity runs both implementations sequentially in the same process so tests can retain returned objects
- Every test saves and restores the original bridge state
- A small subprocess smoke test verifies environment-based startup configuration and detects fallback to the Python HTTP implementation
## Streaming execution
The invocation callback passed to `run_in_process` must consume the stream before returning its `StreamOutcome`.
Use `consume_sync_stream` inside that callback, or await `consume_async_stream` inside the callback passed to
`run_in_process_async`. Provider requests are collected only after the callback completes. Streaming is explicit:
an iterable return value alone does not select stream consumption
The consumers retain the wrapper type, iteration capabilities, chunk types and order, and any partial output before
an error. Errors retain their creation or iteration phase and the full public `SDKError` fields, with traceback text
removed. `capture_sync_stream` and `capture_async_stream` consume through the same helpers and then serialize the
outcome for subprocess reports. A serialization failure raises as a harness failure rather than becoming an SDK error
Response models and stream chunks share a recursive comparator. It compares concrete model, container, and scalar
types, public fields and extras, and exact values while ignoring Pydantic private attributes at every nesting level.
An API may supply an explicit chunk normalizer for its public contract
Shared tests exercise a local SSE provider through recording, VCR cassette storage, replay, and typed event comparison
in sync and async modes. They cover fragmented events, split UTF-8 characters, CRLF framing, coalesced events, and
application errors within a normally completed HTTP stream. HTTP byte boundaries and decoded SDK event boundaries
are checked separately
OCR remains the only integrated LiteLLM route. These tests validate shared streaming machinery, not another route's
SDK parity. Connection interruption, early cancellation, and lifecycle timeout enforcement remain outside this coverage
## Hypothesis and property-based testing
- Hypothesis is a Python library for property-based testing
- Example-based tests use inputs selected by the test author
- Property-based tests define strategies for valid inputs and properties that must hold for every generated example
- Hypothesis generates combinations from those strategies and normally shrinks a failing example to a smaller reproducible case
- In this harness, Hypothesis is used only during fixture generation to expand the LiteLLM input corpus
- Each API owns the strategies that vary its supported inputs
- Fixture generation is deterministic, and each generated input is recorded with the raw provider response it received
- The parity tests use committed fixtures and do not call the provider or generate new Hypothesis examples
- Provider responses are replayed unchanged, so the parity test does not fuzz or validate provider behavior
- Because Hypothesis does not run the parity assertion directly, parity failures are not automatically shrunk
## API-owned fixtures
The shared package owns recording, replay, persistence, execution, comparison, and route-neutral media constructors.
Each API package owns its input models, explicit strategies, provider targets, route-specific assets, fixture directory,
and regeneration command. See the API package documentation for its configured contracts and recording command
## VCR cassettes
Fixtures use VCR's YAML `version: 1` format with ordered request/response `interactions`. VCR handles text and binary
body serialization. Each cassette also contains `recorded_at`, `ttl_seconds: 0` (committed fixtures never expire), and
`x-litellm` metadata holding the SDK input and request provenance. Streaming responses carry
`x-litellm-chunk-lengths` so local replay preserves the original byte boundaries
The recording server captures requests before forwarding their responses. Saved requests use the stable
`http://parity-provider.invalid` origin and strip authentication headers and credential query parameters. The upstream
request keeps its credentials. Provider response bytes and non-success statuses are preserved
Standard VCR can load these files and replay their interactions. Parity tests keep using the local HTTP server because
Rust HTTP calls do not pass through VCR's Python patches. The harness still compares the two implementations' requests
against each other; the saved request is available for inspection and VCR playback, not a new parity assertion
Refresh parity cassettes through the API's recording command. Generic VCR writers do not preserve the SDK metadata
Legacy JSON fixtures remain readable. Migrated cassettes mark reconstructed requests as `python_replay`; fresh
recordings use `recorded`. The metadata extensions follow the filesystem cassette layout proposed in
[PR #39338](https://github.com/BerriAI/litellm/pull/39338), without depending on its unmerged persistence backend
## References
- [Hypothesis documentation](https://hypothesis.readthedocs.io/en/latest/)
- [Hypothesis documentation source](https://github.com/HypothesisWorks/hypothesis/tree/master/hypothesis/docs)

View file

@ -0,0 +1,3 @@
import pytest
pytest.register_assert_rewrite("tests.rust-python-harness.shared.parity.compare")

View file

@ -0,0 +1,80 @@
from __future__ import annotations
from collections.abc import Mapping, Sequence
from typing import Final, cast
from pydantic import BaseModel
from .models import CapturedRequest, Execution
def validate_harness(baseline: Execution, candidate: Execution, baseline_user_agent: str) -> None:
for request in baseline.requests:
if request.user_agent != baseline_user_agent:
raise AssertionError(
f"baseline provider request did not carry sentinel user-agent {baseline_user_agent!r}: "
f"{request.user_agent!r}"
)
for request in candidate.requests:
if request.user_agent == baseline_user_agent:
raise AssertionError("candidate route fell back to the baseline HTTP implementation")
def _request_after_transformation(request: CapturedRequest) -> CapturedRequest:
return request.model_copy(update={"user_agent": None})
def assert_request_parity(baseline: tuple[CapturedRequest, ...], candidate: tuple[CapturedRequest, ...]) -> None:
baseline_requests: Final = tuple(_request_after_transformation(request) for request in baseline)
candidate_requests: Final = tuple(_request_after_transformation(request) for request in candidate)
assert_value_parity(baseline_requests, candidate_requests)
def _public_model_values(model: BaseModel) -> dict[str, object]:
fields: Final = (*type(model).model_fields, *type(model).model_computed_fields)
extras: Final = cast(Mapping[str, object], model.model_extra or {})
return {
**{name: cast(object, getattr(model, name)) for name in fields if not name.startswith("_")},
**{name: value for name, value in extras.items() if not name.startswith("_")},
}
def assert_model_parity(baseline: BaseModel, candidate: BaseModel) -> None:
assert_value_parity(baseline, candidate)
def assert_value_parity(baseline: object, candidate: object, *, path: str = "$") -> None:
assert type(baseline) is type(candidate), f"type mismatch at {path}: {type(baseline)} != {type(candidate)}"
if isinstance(baseline, BaseModel) and isinstance(candidate, BaseModel):
assert_value_parity(_public_model_values(baseline), _public_model_values(candidate), path=path)
return
if isinstance(baseline, Mapping) and isinstance(candidate, Mapping):
baseline_mapping: Final = cast(Mapping[object, object], baseline)
candidate_mapping: Final = cast(Mapping[object, object], candidate)
assert frozenset((type(key), key) for key in baseline_mapping) == frozenset(
(type(key), key) for key in candidate_mapping
), f"mapping keys differ at {path}"
for key in baseline_mapping:
assert_value_parity(baseline_mapping[key], candidate_mapping[key], path=f"{path}.{key}")
return
if (
isinstance(baseline, Sequence)
and not isinstance(baseline, (str, bytes))
and isinstance(candidate, Sequence)
and not isinstance(candidate, (str, bytes))
):
baseline_sequence: Final = cast(Sequence[object], baseline)
candidate_sequence: Final = cast(Sequence[object], candidate)
assert len(baseline_sequence) == len(candidate_sequence), f"sequence lengths differ at {path}"
for index, (baseline_item, candidate_item) in enumerate(
zip(baseline_sequence, candidate_sequence, strict=True)
):
assert_value_parity(baseline_item, candidate_item, path=f"{path}[{index}]")
return
assert baseline == candidate, f"value mismatch at {path}: {baseline!r} != {candidate!r}"
def assert_parity(baseline: Execution, candidate: Execution, baseline_user_agent: str) -> None:
validate_harness(baseline, candidate, baseline_user_agent)
assert_request_parity(baseline.requests, candidate.requests)
assert_value_parity(baseline.report, candidate.report)

View file

@ -0,0 +1,64 @@
from __future__ import annotations
from collections.abc import Mapping
from typing import ClassVar, Final, Generic, Literal, TypeVar, cast
from pydantic import BaseModel, ConfigDict, Field, JsonValue, model_validator
from .recorded_http import RecordedResponse
JsonObject = dict[str, JsonValue]
class FixtureModel(BaseModel):
model_config = ConfigDict(frozen=True, extra="forbid", populate_by_name=True, serialize_by_alias=True)
class SdkInputBase(FixtureModel):
fixture_only_fields: ClassVar[tuple[str, ...]] = ()
def as_sdk_kwargs(self) -> dict[str, object]:
return cast(
dict[str, object],
self.model_dump(
mode="python",
exclude_unset=True,
exclude=set(self.fixture_only_fields),
),
)
def canonical_input(self) -> dict[str, object]:
dumped: Final = cast(dict[str, object], self.model_dump(mode="json", exclude_unset=True))
fixture_fields: Final = {field: getattr(self, field) for field in self.fixture_only_fields}
return {**fixture_fields, **dumped}
class JsonSchemaDefinition(FixtureModel):
name: str
description: str | None = None
schema_definition: JsonObject = Field(alias="schema")
strict: bool = False
class JsonSchemaResponseFormat(FixtureModel):
type: Literal["json_schema"]
json_schema: JsonSchemaDefinition
InputT = TypeVar("InputT", bound=SdkInputBase)
class ParityCase(FixtureModel, Generic[InputT]):
litellm_input: InputT
provider_responses: tuple[RecordedResponse, ...]
@model_validator(mode="before")
@classmethod
def load_legacy_single_response(cls, value: object) -> object:
if not isinstance(value, Mapping):
return value
migrated: Final = dict(cast(Mapping[str, object], value))
provider_response: Final = migrated.pop("provider_response", None)
if "provider_responses" not in migrated and provider_response is not None:
migrated["provider_responses"] = (provider_response,)
return migrated

View file

@ -0,0 +1 @@
from __future__ import annotations

View file

@ -0,0 +1,147 @@
from __future__ import annotations
from collections.abc import Mapping
from datetime import datetime
from itertools import accumulate
from typing import Final, Literal
from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, TypeAdapter
from vcr.serialize import serialize
from vcr.serializers import yamlserializer
from .recording import RecordedInteraction
from ..recorded_http import (
HttpHeader,
RecordedHttpResponse,
RecordedHttpStreamResponse,
RecordedResponse,
RecordedStreamChunk,
)
_OBJECT: Final = TypeAdapter(dict[str, object])
class _CassetteModel(BaseModel):
model_config = ConfigDict(frozen=True, extra="forbid", populate_by_name=True)
class _Body(_CassetteModel):
string: str | bytes
def as_bytes(self) -> bytes:
return self.string.encode("utf-8") if isinstance(self.string, str) else self.string
class _Status(_CassetteModel):
code: int
message: str
class _Request(_CassetteModel):
method: str
uri: str
body: str | bytes | None
headers: dict[str, tuple[str, ...]]
class _Response(_CassetteModel):
status: _Status
headers: dict[str, tuple[str, ...]]
body: _Body
chunk_lengths: tuple[int, ...] | None = Field(default=None, alias="x-litellm-chunk-lengths")
def recorded_response(self) -> RecordedResponse:
headers: Final = tuple(
HttpHeader(name=name, value=value) for name, values in self.headers.items() for value in values
)
body: Final = self.body.as_bytes()
if self.chunk_lengths is None:
return RecordedHttpResponse.from_bytes(self.status.code, headers, body)
if any(length < 0 for length in self.chunk_lengths) or sum(self.chunk_lengths) != len(body):
raise ValueError("cassette stream chunk lengths do not match the response body")
offsets: Final = tuple(accumulate(self.chunk_lengths, initial=0))
return RecordedHttpStreamResponse(
kind="http_stream",
status_code=self.status.code,
headers=headers,
chunks=tuple(RecordedStreamChunk.from_bytes(body[start:end]) for start, end in zip(offsets, offsets[1:])),
)
class _Interaction(_CassetteModel):
request: _Request
response: _Response
class _ParityMetadata(_CassetteModel):
schema_version: Literal[1]
request_source: Literal["recorded", "python_replay"]
case: dict[str, object]
class ParityCassette(_CassetteModel):
version: Literal[1]
recorded_at: AwareDatetime
ttl_seconds: Literal[0]
interactions: tuple[_Interaction, ...]
parity: _ParityMetadata = Field(alias="x-litellm")
def case_data(self) -> dict[str, object]:
return {
**self.parity.case,
"provider_responses": tuple(item.response.recorded_response() for item in self.interactions),
}
def _response_dict(response: RecordedResponse) -> dict[str, object]:
headers: Final = {
name: [header.value for header in response.headers if header.name == name]
for name in dict.fromkeys(header.name for header in response.headers)
}
chunks: Final = (
tuple(chunk.data_bytes() for chunk in response.chunks)
if isinstance(response, RecordedHttpStreamResponse)
else None
)
body: Final = response.body_bytes() if isinstance(response, RecordedHttpResponse) else b"".join(chunks or ())
return {
"status": {"code": response.status_code, "message": ""},
"headers": headers,
"body": {"string": body},
**({"x-litellm-chunk-lengths": list(map(len, chunks))} if chunks is not None else {}),
}
def serialize_cassette(
case: Mapping[str, object],
interactions: tuple[RecordedInteraction, ...],
recorded_at: datetime,
request_source: Literal["recorded", "python_replay"],
) -> str:
normalized: Final = _OBJECT.validate_python(
yamlserializer.deserialize(
serialize(
{
"requests": [item.request for item in interactions],
"responses": [_response_dict(item.response) for item in interactions],
},
yamlserializer,
)
)
)
payload: Final = {
**normalized,
"recorded_at": recorded_at.isoformat(),
"ttl_seconds": 0,
"x-litellm": {
"schema_version": 1,
"request_source": request_source,
"case": {key: value for key, value in case.items() if key != "provider_responses"},
},
}
ParityCassette.model_validate(payload).case_data()
return str(yamlserializer.serialize(payload))
def deserialize_cassette(contents: str) -> ParityCassette:
return ParityCassette.model_validate(yamlserializer.deserialize(contents))

View file

@ -0,0 +1,34 @@
from __future__ import annotations
import argparse
from collections.abc import Sequence
from dataclasses import dataclass
from pathlib import Path
from typing import Final, cast
@dataclass(frozen=True, slots=True)
class RecordingArgs:
concurrency: int
examples: int
fixture_dir: Path | None
def _positive_int(value: str) -> int:
parsed: Final = int(value)
if parsed < 1:
raise argparse.ArgumentTypeError("must be at least 1")
return parsed
def parse_recording_args(argv: Sequence[str] | None = None) -> RecordingArgs:
parser: Final = argparse.ArgumentParser()
parser.add_argument("--concurrency", type=_positive_int, default=4)
parser.add_argument("--examples", type=_positive_int, default=4)
parser.add_argument("--fixture-dir", type=Path)
namespace: Final = parser.parse_args(argv)
return RecordingArgs(
concurrency=cast(int, namespace.concurrency),
examples=cast(int, namespace.examples),
fixture_dir=cast(Path | None, namespace.fixture_dir),
)

View file

@ -0,0 +1,22 @@
from __future__ import annotations
import queue
from typing import Final, TypeVar
from hypothesis import given, settings
from hypothesis.strategies import SearchStrategy
InputT = TypeVar("InputT")
def generate_case_inputs(strategy: SearchStrategy[InputT], examples: int) -> tuple[InputT, ...]:
generated: Final[queue.SimpleQueue[InputT | None]] = queue.SimpleQueue()
@settings(max_examples=examples, deadline=None, derandomize=True)
@given(case_input=strategy)
def generate_case(case_input: InputT) -> None:
generated.put(case_input)
generate_case()
generated.put(None)
return tuple(iter(generated.get, None))

View file

@ -0,0 +1,225 @@
from __future__ import annotations
import base64
from functools import cache
from io import BytesIO
from typing import Final
from urllib.parse import quote
from PIL import Image, ImageDraw
from reportlab.graphics.barcode import code128 # pyright: ignore[reportMissingTypeStubs] # ReportLab has no stubs
from reportlab.lib import colors # pyright: ignore[reportMissingTypeStubs] # ReportLab has no stubs
from reportlab.lib.pagesizes import letter # pyright: ignore[reportMissingTypeStubs] # ReportLab has no stubs
from reportlab.lib.utils import ImageReader # pyright: ignore[reportMissingTypeStubs] # ReportLab has no stubs
from reportlab.pdfgen import canvas # pyright: ignore[reportMissingTypeStubs] # ReportLab has no stubs
def dummy_image_url(text: str, font_size: int, width: int = 800, height: int = 300) -> str:
return f"https://dummyjson.com/image/{width}x{height}/ffffff/000000?text={quote(text)}&fontSize={font_size}"
_GLYPHS: Final = {
"D": ("11110", "10001", "10001", "10001", "10001", "10001", "11110"),
"O": ("01110", "10001", "10001", "10001", "10001", "10001", "01110"),
"C": ("01111", "10000", "10000", "10000", "10000", "10000", "01111"),
"1": ("00100", "01100", "00100", "00100", "00100", "00100", "01110"),
"2": ("01110", "10001", "00001", "00010", "00100", "01000", "11111"),
"3": ("11110", "00001", "00001", "01110", "00001", "00001", "11110"),
}
@cache
def structured_image_bytes() -> bytes:
image: Final = Image.new("RGB", (320, 80), "white")
draw: Final = ImageDraw.Draw(image)
scale: Final = 8
cursor_x = 24
for character in "DOC 123":
if character == " ":
cursor_x += scale * 3
continue
for glyph_y, row in enumerate(_GLYPHS[character]):
for glyph_x, filled in enumerate(row):
if filled == "1":
x = cursor_x + glyph_x * scale
y = 12 + glyph_y * scale
draw.rectangle((x, y, x + scale - 1, y + scale - 1), fill="black")
cursor_x += scale * 6
output: Final = BytesIO()
image.save(output, format="PNG")
return output.getvalue()
@cache
def structured_image_data_uri() -> str:
encoded: Final = base64.b64encode(structured_image_bytes()).decode("ascii")
return f"data:image/png;base64,{encoded}"
def _draw_header(pdf: canvas.Canvas, title: str, page_number: int) -> None:
pdf.setFillColor(colors.black)
pdf.setFont("Helvetica", 11)
pdf.drawString(45, 770, "Quarterly Operations Report")
pdf.setFont("Helvetica-Bold", 16)
pdf.drawString(45, 745, title)
pdf.setFont("Helvetica", 9)
pdf.drawString(45, 30, f"Confidential | Page {page_number} of 5")
def _draw_body(pdf: canvas.Canvas, page_number: int) -> None:
pdf.setFont("Helvetica", 10)
for line_number in range(1, 9):
pdf.drawString(
45,
500 - (line_number * 28),
f"Section {page_number}.{line_number}: Invoice totals, regional revenue, and reconciliation notes.",
)
def _diagram_image(width: int, height: int, accent: tuple[int, int, int]) -> Image.Image:
image: Final = Image.new("RGB", (width, height), (242, 246, 252))
draw: Final = ImageDraw.Draw(image)
for coordinate in range(0, max(width, height), 40):
draw.line((coordinate, 0, coordinate, height), fill=(32, 32, 32), width=3)
draw.line((0, coordinate, width, coordinate), fill=(32, 32, 32), width=3)
draw.line((0, 0, width, height), fill=accent, width=8)
draw.line((width, 0, 0, height), fill=accent, width=8)
draw.rectangle((width // 4, height // 4, width * 3 // 4, height * 3 // 4), outline=accent, width=6)
return image
def _draw_embedded_images(pdf: canvas.Canvas) -> None:
images: Final = (
(_diagram_image(320, 320, (51, 115, 217)), 455, 655, 70, 70),
(_diagram_image(360, 320, (38, 151, 92)), 455, 565, 70, 62),
(_diagram_image(120, 120, (219, 68, 55)), 455, 500, 45, 45),
)
for image, x, y, width, height in images:
pdf.drawImage( # pyright: ignore[reportUnknownMemberType] # ReportLab has no stubs
ImageReader(image), x, y, width=width, height=height, mask="auto"
)
def _draw_table_page(pdf: canvas.Canvas) -> None:
columns: Final = (45, 245, 405, 565)
tables: Final = (
(
(730, 695, 660, 625),
(
("Item", "Quantity", "Amount", 707),
("Document analysis", "2", "120.00", 672),
("Document verification", "1", "80.00", 637),
),
),
(
(600, 565, 530, 495),
(
("Item continued", "Quantity", "Amount", 577),
("Fixture validation", "3", "45.00", 542),
("Provider review", "1", "25.00", 507),
),
),
)
for rows, values in tables:
for x in columns:
pdf.line(x, rows[-1], x, rows[0])
for y in rows:
pdf.line(45, y, 565, y)
for item, quantity, amount, y in values:
pdf.drawString(55, y, item)
pdf.drawString(255, y, quantity)
pdf.drawString(415, y, amount)
def _draw_chart_page(pdf: canvas.Canvas) -> None:
bars: Final = ((70, 70), (170, 115), (270, 90), (370, 130))
pdf.setFillColor(colors.HexColor("#3373D9"))
for x, height in bars:
pdf.rect(x, 610, 65, height, fill=1, stroke=0)
pdf.setFillColor(colors.black)
for quarter, x in zip(("Q1", "Q2", "Q3", "Q4"), (90, 190, 290, 390), strict=True):
pdf.drawString(x, 590, quarter)
pdf.drawString(45, 550, "Formula: gross margin = (revenue - cost) / revenue")
_draw_embedded_images(pdf)
def _draw_metadata_page(pdf: canvas.Canvas) -> None:
pdf.setFont("Helvetica", 12)
pdf.drawString(45, 700, "Invoice Number: INV-2048")
pdf.drawString(45, 675, "Purchase Order: PO-4096")
pdf.setFillColor(colors.HexColor("#F2E65A"))
pdf.rect(40, 555, 500, 24, fill=1, stroke=0)
pdf.setFillColor(colors.black)
pdf.drawString(45, 560, "Highlighted total requiring review")
pdf.drawString(45, 530, "Reviewer comment: verify the highlighted total before approval")
pdf.setFillColor(colors.red)
pdf.drawString(45, 495, "Revised total: 245.00")
pdf.line(45, 501, 150, 501)
pdf.setFillColor(colors.black)
pdf.linkURL( # pyright: ignore[reportUnknownMemberType] # ReportLab has no stubs
"https://example.com/invoices/INV-2048", (45, 575, 300, 590), relative=0
)
pdf.highlightAnnotation( # pyright: ignore[reportUnknownMemberType] # ReportLab has no stubs
"Total highlighted for review",
Rect=(40, 555, 540, 579),
QuadPoints=(40, 579, 540, 579, 40, 555, 540, 555),
)
pdf.textAnnotation( # pyright: ignore[reportUnknownMemberType] # ReportLab has no stubs
"Verify the highlighted total", Rect=(520, 525, 540, 545)
)
pdf.drawString(45, 575, "https://example.com/invoices/INV-2048")
barcode: Final = code128.Code128("5901234123457", barHeight=70, barWidth=1.2)
barcode.drawOn(pdf, 90, 130)
def _draw_signature_page(pdf: canvas.Canvas) -> None:
pdf.saveState()
pdf.setFillColor(colors.lightgrey)
pdf.setFont("Helvetica-Bold", 54)
pdf.translate(110, 390)
pdf.rotate(25)
pdf.drawString(0, 0, "DRAFT")
pdf.restoreState()
pdf.setFillColor(colors.black)
pdf.setFont("Helvetica", 12)
pdf.drawString(45, 635, "Approved by: Jordan Lee")
pdf.line(45, 610, 310, 610)
pdf.bezier(55, 595, 75, 625, 112, 602, 155, 600)
pdf.drawString(45, 580, "Signature")
def _draw_appendix_page(pdf: canvas.Canvas) -> None:
pdf.setFont("Helvetica-Bold", 14)
pdf.drawString(45, 700, "1. Scope")
pdf.drawString(45, 650, "2. Findings")
pdf.drawString(45, 600, "3. Recommendations")
@cache
def structured_pdf_bytes() -> bytes:
output: Final = BytesIO()
pdf: Final = canvas.Canvas(output, pagesize=letter, pageCompression=0, invariant=1)
pdf.setTitle("Quarterly Operations Report")
pdf.setAuthor("LiteLLM parity fixture generator")
pdf.setSubject("Semantic document coverage for tables, figures, annotations, and metadata")
pdf.setKeywords("document, invoice, table, figure, annotation")
pages: Final = (
("Invoice Summary and Line Items", _draw_table_page),
("Revenue Chart and Formula Review", _draw_chart_page),
("Key Values, Link, Highlight, and Comment", _draw_metadata_page),
("Approval Signature and Watermark", _draw_signature_page),
("Appendix with Section Boundaries", _draw_appendix_page),
)
for page_number, (title, draw_page) in enumerate(pages, start=1):
_draw_header(pdf, title, page_number)
draw_page(pdf)
_draw_body(pdf, page_number)
pdf.showPage()
pdf.save()
return output.getvalue()
@cache
def structured_pdf_data_uri() -> str:
encoded: Final = base64.b64encode(structured_pdf_bytes()).decode("ascii")
return f"data:application/pdf;base64,{encoded}"

View file

@ -0,0 +1,198 @@
from __future__ import annotations
import logging
from concurrent.futures import Future, ThreadPoolExecutor, as_completed
from dataclasses import dataclass, field
from pathlib import Path
from types import MappingProxyType
from typing import Final, Generic, Literal, Protocol, TypeVar
from hypothesis.strategies import SearchStrategy
from pydantic import BaseModel
from .inputs import generate_case_inputs
from .recording import UpstreamEndpoint, record_upstream_interactions
from .store import (
FixtureInput,
canonical_json,
fixture_cache_key,
fixture_id,
fixture_path,
load_fixture,
save_fixture,
)
LOGGER: Final = logging.getLogger(__name__)
InputT = TypeVar("InputT", bound=FixtureInput)
InputT_contra = TypeVar("InputT_contra", bound=FixtureInput, contravariant=True)
CaseT = TypeVar("CaseT", bound=BaseModel)
class RecordingInvocation(Protocol[InputT_contra]):
def execute(self, provider_url: str, case_input: InputT_contra) -> None: ...
@dataclass(frozen=True, slots=True)
class RecordingTarget(Generic[InputT]):
name: str
upstream: UpstreamEndpoint
strategy: SearchStrategy[InputT]
invocation: RecordingInvocation[InputT] = field(repr=False)
required_inputs: tuple[InputT, ...] = ()
@dataclass(frozen=True, slots=True)
class RecordingJob(Generic[InputT]):
target_name: str
directory: Path
upstream: UpstreamEndpoint
case_input: InputT
invocation: RecordingInvocation[InputT] = field(repr=False)
@property
def case_id(self) -> str:
return fixture_id(self.case_input, self.target_name)
@dataclass(frozen=True, slots=True)
class RecordedFixture:
target_name: str
case_id: str
path: Path
kind: Literal["recorded"] = field(default="recorded", init=False)
@dataclass(frozen=True, slots=True)
class CachedFixture:
target_name: str
case_id: str
path: Path
kind: Literal["cached"] = field(default="cached", init=False)
@dataclass(frozen=True, slots=True)
class FailedFixture:
target_name: str
case_id: str
error: Exception = field(repr=False)
kind: Literal["failed"] = field(default="failed", init=False)
RecordingOutcome = RecordedFixture | CachedFixture | FailedFixture
@dataclass(frozen=True, slots=True)
class RecordingSummary:
recorded: tuple[RecordedFixture, ...]
cached: tuple[CachedFixture, ...]
failed: tuple[FailedFixture, ...]
@property
def exit_code(self) -> int:
return 1 if self.failed else 0
def _unique_inputs(target: RecordingTarget[InputT], examples: int) -> tuple[InputT, ...]:
generated_inputs: Final = generate_case_inputs(target.strategy, examples)
case_inputs: Final = (*target.required_inputs, *generated_inputs)
return tuple({canonical_json(fixture_cache_key(case_input)): case_input for case_input in case_inputs}.values())
def build_recording_jobs(
targets: tuple[RecordingTarget[InputT], ...],
root: Path,
examples: int,
) -> tuple[RecordingJob[InputT], ...]:
if examples < 1:
raise ValueError("examples must be at least 1")
return tuple(
RecordingJob(
target_name=target.name,
directory=root / target.name,
upstream=target.upstream,
case_input=case_input,
invocation=target.invocation,
)
for target in targets
for case_input in _unique_inputs(target, examples)
)
def _record_job(job: RecordingJob[InputT], case_type: type[CaseT]) -> RecordedFixture | CachedFixture:
cached: Final = load_fixture(job.directory, job.case_input, case_type)
if cached is not None:
path: Final = fixture_path(job.directory, job.case_input)
return CachedFixture(
target_name=job.target_name,
case_id=job.case_id,
path=path if path.is_file() else path.with_suffix(".json"),
)
interactions: Final = record_upstream_interactions(
job.upstream,
job.case_input,
job.invocation.execute,
)
case: Final = case_type.model_validate(
{
"litellm_input": job.case_input,
"provider_responses": tuple(item.response for item in interactions),
}
)
saved_path: Final = save_fixture(job.directory, job.case_input, case, interactions)
return RecordedFixture(target_name=job.target_name, case_id=job.case_id, path=saved_path)
def _completed_outcome(
completed: int,
total: int,
job: RecordingJob[InputT],
future: Future[RecordedFixture | CachedFixture],
) -> RecordingOutcome:
try:
outcome: Final = future.result()
except Exception as error:
failed: Final = FailedFixture(target_name=job.target_name, case_id=job.case_id, error=error)
LOGGER.error(
"[%d/%d] failed %s %s: %s",
completed,
total,
failed.target_name,
failed.case_id,
type(error).__name__,
)
return failed
LOGGER.info("[%d/%d] %s %s %s", completed, total, outcome.kind, outcome.target_name, outcome.case_id)
return outcome
def record_fixtures(
targets: tuple[RecordingTarget[InputT], ...],
root: Path,
examples: int,
concurrency: int,
case_type: type[CaseT],
) -> RecordingSummary:
if concurrency < 1:
raise ValueError("concurrency must be at least 1")
jobs: Final = build_recording_jobs(targets, root, examples)
total: Final = len(jobs)
LOGGER.info("Recording %d fixtures across %d targets with concurrency %d", total, len(targets), concurrency)
with ThreadPoolExecutor(max_workers=concurrency) as executor:
future_jobs: Final = MappingProxyType({executor.submit(_record_job, job, case_type): job for job in jobs})
outcomes: Final = tuple(
_completed_outcome(completed, total, future_jobs[future], future)
for completed, future in enumerate(as_completed(future_jobs), start=1)
)
summary: Final = RecordingSummary(
recorded=tuple(outcome for outcome in outcomes if isinstance(outcome, RecordedFixture)),
cached=tuple(outcome for outcome in outcomes if isinstance(outcome, CachedFixture)),
failed=tuple(outcome for outcome in outcomes if isinstance(outcome, FailedFixture)),
)
LOGGER.info(
"Finished %d fixtures: %d recorded, %d cached, %d failed",
total,
len(summary.recorded),
len(summary.cached),
len(summary.failed),
)
return summary

View file

@ -0,0 +1,66 @@
from __future__ import annotations
import os
from collections.abc import Callable
from pathlib import Path
from typing import Final, TypeVar
import pytest
from pydantic import BaseModel, ValidationError
from .store import recorded_fixtures
CaseT = TypeVar("CaseT", bound=BaseModel)
def parametrize_recorded_fixtures(
metafunc: pytest.Metafunc,
*,
fixture_name: str,
case_type: type[CaseT],
env_var: str,
default_directory: Path,
regeneration_command: str,
id_builder: Callable[[CaseT], str],
marks_builder: Callable[[CaseT], tuple[pytest.MarkDecorator, ...]] | None = None,
) -> None:
if fixture_name not in metafunc.fixturenames:
return
configured: Final = os.environ.get(env_var)
if configured == "":
raise pytest.UsageError(f"{env_var} is set but empty")
directory: Final = Path(configured).expanduser() if configured is not None else default_directory
try:
fixtures: Final = recorded_fixtures(directory, case_type)
except (ValidationError, ValueError) as error:
raise pytest.UsageError(
f"Invalid parity fixture bundle at {directory}. "
"Each fixture must use the current versioned envelope. "
f"Record fresh fixtures in an empty directory with: `{regeneration_command}`. "
f"Validation details: {error}"
) from error
if fixtures:
metafunc.parametrize(
fixture_name,
tuple(
pytest.param(
fixture,
id=id_builder(fixture),
marks=marks_builder(fixture) if marks_builder is not None else (),
)
for fixture in fixtures
),
)
return
if configured is not None:
raise pytest.UsageError(f"no recorded fixtures in {directory}")
metafunc.parametrize(
fixture_name,
(
pytest.param(
None,
marks=pytest.mark.skip(reason=f"no recorded fixtures in {directory}"),
id="no-recorded-fixtures",
),
),
)

View file

@ -0,0 +1,267 @@
from __future__ import annotations
import queue
import threading
from collections.abc import Callable, Generator, Iterable
from contextlib import contextmanager
from dataclasses import dataclass
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from typing import Final, TypeVar, cast
from urllib.parse import urlsplit, urlunsplit
import httpx
from vcr.filters import remove_query_parameters
from vcr.request import Request
from ..http import (
dropped_request_headers,
dropped_response_headers,
is_streaming_response,
)
from ..recorded_http import (
HttpHeader,
RecordedHttpResponse,
RecordedHttpStreamResponse,
RecordedResponse,
RecordedStreamChunk,
)
_PARITY_PROVIDER_HOST: Final = "parity-provider.invalid"
_SECRET_HEADERS: Final = frozenset(
{
"authorization",
"proxy-authorization",
"cookie",
"x-api-key",
"api-key",
"anthropic-api-key",
"openai-api-key",
"azure-api-key",
"x-goog-api-key",
"ocp-apim-subscription-key",
"x-amz-security-token",
}
)
InputT = TypeVar("InputT")
@dataclass(frozen=True, slots=True)
class UpstreamEndpoint:
base_url: str
@dataclass(frozen=True, slots=True)
class RecordedInteraction:
request: Request
response: RecordedResponse
def _end_to_end_headers(headers: httpx.Headers) -> tuple[HttpHeader, ...]:
decoded: Final = tuple((name.decode("ascii"), value.decode("latin-1")) for name, value in headers.raw)
excluded: Final = dropped_response_headers(decoded)
return tuple(
HttpHeader(name=name, value=_normalized_response_header(name, value))
for name, value in decoded
if name.lower() not in excluded
)
def _normalized_response_header(name: str, value: str) -> str:
if name.lower() not in {"location", "operation-location"}:
return value
parsed: Final = urlsplit(value)
if not parsed.netloc:
return value
return urlunsplit(("http", _PARITY_PROVIDER_HOST, parsed.path, parsed.query, parsed.fragment))
def local_response_header(name: str, value: str, provider_url: str) -> str:
if name.lower() not in {"location", "operation-location"}:
return value
parsed: Final = urlsplit(value)
if parsed.hostname != _PARITY_PROVIDER_HOST:
return value
return f"{provider_url}{parsed.path}{'?' + parsed.query if parsed.query else ''}"
class _RecordingProvider(ThreadingHTTPServer):
daemon_threads = True
def __init__(self, spec: UpstreamEndpoint) -> None:
super().__init__(("127.0.0.1", 0), _RecordingHandler)
self.spec: Final = spec
self.interactions: queue.Queue[RecordedInteraction] = queue.Queue()
@property
def url(self) -> str:
return f"http://127.0.0.1:{self.server_address[1]}"
def take_interactions(self) -> tuple[RecordedInteraction, ...]:
try:
first: Final = self.interactions.get(timeout=5)
except queue.Empty as error:
raise RuntimeError("successful SDK call did not produce a recorded response") from error
remaining: Final = tuple(self.interactions.get_nowait() for _ in range(self.interactions.qsize()))
return (first, *remaining)
class _RecordingHandler(BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"
def do_POST(self) -> None:
self._forward()
def do_GET(self) -> None:
self._forward()
def do_PUT(self) -> None:
self._forward()
def do_PATCH(self) -> None:
self._forward()
def do_DELETE(self) -> None:
self._forward()
def _forward(self) -> None:
provider: Final = self.server
assert isinstance(provider, _RecordingProvider)
length: Final = int(self.headers.get("content-length") or "0")
request_body: Final = self.rfile.read(length) if length else b""
raw_headers: Final = tuple(self.headers.raw_items())
excluded: Final = dropped_request_headers(raw_headers)
forwarded_headers: Final = tuple((name, value) for name, value in raw_headers if name.lower() not in excluded)
upstream_url: Final = f"{provider.spec.base_url.rstrip('/')}{self.path}"
try:
with httpx.stream(
self.command,
upstream_url,
headers=forwarded_headers,
content=request_body,
timeout=120,
) as upstream:
headers: Final = _end_to_end_headers(upstream.headers)
recorded_response: Final = self._record_upstream_response(upstream, headers)
except httpx.HTTPError as error:
self._send_response(502, (), str(error).encode("utf-8"))
return
recorded_request: Final = remove_query_parameters(
Request(
self.command,
f"http://{_PARITY_PROVIDER_HOST}{self.path}",
request_body,
{name: value for name, value in forwarded_headers if name.lower() not in _SECRET_HEADERS},
),
("api_key", "api-key", "key", "access_token", "subscription-key"),
)
provider.interactions.put(RecordedInteraction(recorded_request, recorded_response))
if isinstance(recorded_response, RecordedHttpResponse):
self._send_response(
recorded_response.status_code, recorded_response.headers, recorded_response.body_bytes()
)
def _record_upstream_response(
self,
upstream: httpx.Response,
headers: tuple[HttpHeader, ...],
) -> RecordedResponse:
content_type: Final = cast(str, upstream.headers.get("content-type", ""))
if is_streaming_response(content_type):
return self._record_stream(upstream, headers)
response_body: Final = b"".join(upstream.iter_bytes())
return RecordedHttpResponse.from_bytes(
status_code=upstream.status_code,
headers=headers,
body=response_body,
)
def _record_stream(
self,
upstream: httpx.Response,
headers: tuple[HttpHeader, ...],
) -> RecordedHttpStreamResponse:
self.send_response_only(upstream.status_code)
provider: Final = self.server
assert isinstance(provider, _RecordingProvider)
for header in headers:
self.send_header(header.name, local_response_header(header.name, header.value, provider.url))
self.send_header("transfer-encoding", "chunked")
self.end_headers()
chunks: Final = tuple(self._relay_chunks(upstream.iter_bytes()))
self.wfile.write(b"0\r\n\r\n")
self.wfile.flush()
return RecordedHttpStreamResponse(
kind="http_stream",
status_code=upstream.status_code,
headers=headers,
chunks=chunks,
)
def _relay_chunks(self, chunks: Iterable[bytes]) -> Generator[RecordedStreamChunk, None, None]:
for chunk in chunks:
self.wfile.write(f"{len(chunk):X}\r\n".encode("ascii"))
self.wfile.write(chunk)
self.wfile.write(b"\r\n")
self.wfile.flush()
yield RecordedStreamChunk.from_bytes(chunk)
def _send_response(self, status_code: int, headers: tuple[HttpHeader, ...], body: bytes) -> None:
self.send_response_only(status_code)
provider: Final = self.server
assert isinstance(provider, _RecordingProvider)
for header in headers:
self.send_header(header.name, local_response_header(header.name, header.value, provider.url))
self.send_header("content-length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, format: str, *args: object) -> None:
return
@contextmanager
def _recording_provider(spec: UpstreamEndpoint) -> Generator[_RecordingProvider]:
server: Final = _RecordingProvider(spec)
thread: Final = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
try:
yield server
finally:
server.shutdown()
server.server_close()
thread.join(timeout=5)
def _invoke_and_take_interactions(
recorder: _RecordingProvider,
case_input: InputT,
sdk_call: Callable[[str, InputT], object],
) -> tuple[RecordedInteraction, ...]:
try:
sdk_call(recorder.url, case_input)
except Exception as invocation_error:
try:
return recorder.take_interactions()
except RuntimeError:
raise invocation_error
return recorder.take_interactions()
def record_upstream_interactions(
spec: UpstreamEndpoint,
case_input: InputT,
sdk_call: Callable[[str, InputT], object],
) -> tuple[RecordedInteraction, ...]:
with _recording_provider(spec) as recorder:
return _invoke_and_take_interactions(recorder, case_input, sdk_call)
def record_upstream_responses(
spec: UpstreamEndpoint,
case_input: InputT,
sdk_call: Callable[[str, InputT], object],
) -> tuple[RecordedResponse, ...]:
return tuple(item.response for item in record_upstream_interactions(spec, case_input, sdk_call))

View file

@ -0,0 +1,126 @@
from __future__ import annotations
import hashlib
import json
import tempfile
from collections.abc import Mapping
from datetime import datetime, timezone
from pathlib import Path
from typing import Final, Literal, Protocol, TypeVar, cast
from pydantic import AwareDatetime, BaseModel, ConfigDict, TypeAdapter, ValidationError
from .cassette import deserialize_cassette, serialize_cassette
from .recording import RecordedInteraction
FIXTURE_SCHEMA_VERSION: Final = 1
JSON_OBJECT: Final = TypeAdapter(dict[str, object])
class FixtureInput(Protocol):
def canonical_input(self) -> dict[str, object]: ...
CaseT = TypeVar("CaseT", bound=BaseModel)
class FixtureEnvelope(BaseModel):
model_config = ConfigDict(frozen=True, extra="forbid")
schema_version: int
recorded_at: AwareDatetime
case: dict[str, object]
def canonical_json(value: Mapping[str, object]) -> str:
return json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=True)
def fixture_cache_key(case_input: FixtureInput) -> dict[str, object]:
return case_input.canonical_input()
def fixture_path(directory: Path, case_input: FixtureInput) -> Path:
input_json: Final = canonical_json(fixture_cache_key(case_input))
digest: Final = hashlib.sha256(input_json.encode("utf-8")).hexdigest()
return directory / f"{digest}.yaml"
def load_fixture(directory: Path, case_input: FixtureInput, case_type: type[CaseT]) -> CaseT | None:
path: Final = fixture_path(directory, case_input)
if path.is_file():
return read_fixture(path, case_type)
legacy_path: Final = path.with_suffix(".json")
if not legacy_path.is_file():
return None
return read_fixture(legacy_path, case_type)
def save_fixture(
directory: Path,
case_input: FixtureInput,
case: BaseModel,
interactions: tuple[RecordedInteraction, ...],
*,
recorded_at: datetime | None = None,
request_source: Literal["recorded", "python_replay"] = "recorded",
) -> Path:
directory.mkdir(parents=True, exist_ok=True)
path: Final = fixture_path(directory, case_input)
serialized: Final = serialize_cassette(
cast(dict[str, object], case.model_dump(mode="json", exclude_unset=True)),
interactions,
recorded_at or datetime.now(timezone.utc),
request_source,
)
with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", dir=directory, delete=False) as temporary:
temporary_path: Final = Path(temporary.name)
try:
temporary.write(serialized)
temporary.close()
temporary_path.replace(path)
finally:
temporary_path.unlink(missing_ok=True)
return path
def read_fixture(path: Path, case_type: type[CaseT]) -> CaseT:
contents: Final = path.read_text(encoding="utf-8")
if path.suffix == ".json":
return _load_fixture(JSON_OBJECT.validate_json(contents), path, case_type)
try:
cassette: Final = deserialize_cassette(contents)
return case_type.model_validate(cassette.case_data())
except ValueError as error:
raise ValueError(f"invalid parity cassette {path}") from error
def _load_fixture(raw_fixture: dict[str, object], path: Path, case_type: type[CaseT]) -> CaseT:
schema_version: Final = raw_fixture.get("schema_version")
if schema_version != FIXTURE_SCHEMA_VERSION:
raise ValueError(
f"fixture {path} has schema_version {schema_version!r}, expected {FIXTURE_SCHEMA_VERSION}; "
"delete it and regenerate the fixture bundle"
)
try:
envelope: Final = FixtureEnvelope.model_validate(raw_fixture)
return case_type.model_validate(envelope.case)
except ValidationError as error:
raise ValueError(f"invalid parity fixture {path} ({len(error.errors())} validation errors)") from error
def recorded_fixtures(directory: Path, case_type: type[CaseT]) -> tuple[CaseT, ...]:
if not directory.is_dir():
return ()
paths: Final = tuple(sorted((*directory.rglob("*.yaml"), *directory.rglob("*.json"))))
return tuple(read_fixture(path, case_type) for path in paths)
def fixture_directory(configured: Path | None, env_value: str | None, default: Path) -> Path:
return (configured or Path(env_value or default)).expanduser()
def fixture_id(case_input: FixtureInput, prefix: str) -> str:
input_json: Final = canonical_json(case_input.canonical_input())
digest: Final = hashlib.sha256(input_json.encode("utf-8")).hexdigest()[:8]
return f"{prefix}-{digest}"

View file

@ -0,0 +1,95 @@
from __future__ import annotations
from datetime import datetime, timezone
from pathlib import Path
from typing import Final
import httpx
import pytest
from vcr import VCR
from vcr.request import Request
from ..fixture_models import ParityCase, SdkInputBase
from .cassette import deserialize_cassette
from .recording import RecordedInteraction
from .store import load_fixture, save_fixture
from ..recorded_http import (
HttpHeader,
RecordedHttpResponse,
RecordedHttpStreamResponse,
RecordedResponse,
RecordedStreamChunk,
)
from ..replay import replay_server
_URI: Final = "http://parity-provider.invalid/operation?api-version=1"
class _Input(SdkInputBase):
model: str = "fixture-model"
@pytest.mark.parametrize("body", (b'{"text":"caf\xc3\xa9"}', b"\x00\xff\x80", b""))
def test_cassette_replays_repeated_requests_with_vcr_and_preserves_bytes(tmp_path: Path, body: bytes) -> None:
sdk_input: Final = _Input()
responses: Final = tuple(
RecordedHttpResponse.from_bytes(
status,
(HttpHeader(name="content-type", value="application/octet-stream"),),
body,
)
for status in (200, 429)
)
case: Final = ParityCase[_Input](litellm_input=sdk_input, provider_responses=responses)
interactions: Final = tuple(
RecordedInteraction(Request("POST", _URI, b"\xffrequest", {}), response) for response in responses
)
timestamp: Final = datetime(2020, 1, 1, tzinfo=timezone.utc)
path: Final = save_fixture(tmp_path, sdk_input, case, interactions, recorded_at=timestamp)
assert load_fixture(tmp_path, sdk_input, ParityCase[_Input]) == case
assert deserialize_cassette(path.read_text()).recorded_at == timestamp
with VCR().use_cassette(str(path), record_mode="none", match_on=("method", "uri", "body")) as cassette:
for status in (200, 429):
replayed: Final = httpx.post(_URI, content=b"\xffrequest")
assert replayed.status_code == status
assert replayed.content == body
assert cassette.all_played
def test_stream_cassette_preserves_chunk_boundaries_through_local_replay(tmp_path: Path) -> None:
sdk_input: Final = _Input()
chunks: Final = (b"data: caf\xc3", b"\xa9\n\n", b"data: [DONE]\n\n")
response: Final = RecordedHttpStreamResponse(
kind="http_stream",
status_code=200,
headers=(HttpHeader(name="content-type", value="text/event-stream"),),
chunks=tuple(RecordedStreamChunk.from_bytes(chunk) for chunk in chunks),
)
case: Final = ParityCase[_Input](litellm_input=sdk_input, provider_responses=(response,))
path: Final = save_fixture(
tmp_path, sdk_input, case, (RecordedInteraction(Request("POST", _URI, b"{}", {}), response),)
)
loaded: Final = load_fixture(tmp_path, sdk_input, ParityCase[_Input])
assert loaded == case
with replay_server() as server:
server.enqueue_response(loaded.provider_responses[0])
with httpx.stream("POST", f"{server.url}/operation", content=b"{}") as replayed:
assert tuple(replayed.iter_raw()) == chunks
server.take_requests(1)
path.write_text(path.read_text().replace("- 10\n", "- 999\n"))
with pytest.raises(ValueError, match="invalid parity cassette"):
load_fixture(tmp_path, sdk_input, ParityCase[_Input])
def test_cassette_preserves_duplicate_response_headers(tmp_path: Path) -> None:
sdk_input: Final = _Input()
response: Final[RecordedResponse] = RecordedHttpResponse.from_bytes(
200,
(HttpHeader(name="x-test", value="first"), HttpHeader(name="x-test", value="second")),
b"{}",
)
case: Final = ParityCase[_Input](litellm_input=sdk_input, provider_responses=(response,))
save_fixture(tmp_path, sdk_input, case, (RecordedInteraction(Request("POST", _URI, b"", {}), response),))
assert load_fixture(tmp_path, sdk_input, ParityCase[_Input]) == case

View file

@ -0,0 +1,20 @@
from __future__ import annotations
from typing import Final
from hypothesis import strategies as st
from pydantic import BaseModel, ConfigDict
from .inputs import generate_case_inputs
class _Input(BaseModel):
model_config = ConfigDict(frozen=True, extra="forbid")
identifier: str
def test_generate_case_inputs_is_deterministic() -> None:
strategy: Final = st.builds(_Input, identifier=st.integers().map(str))
assert generate_case_inputs(strategy, examples=4) == generate_case_inputs(strategy, examples=4)

View file

@ -0,0 +1,27 @@
from __future__ import annotations
import base64
from io import BytesIO
from typing import Final, cast
from PIL import Image
from .media import dummy_image_url, structured_image_bytes, structured_image_data_uri
def test_dummy_image_url_encodes_text_and_dimensions() -> None:
assert dummy_image_url("invoice 123", 24, width=320, height=80) == (
"https://dummyjson.com/image/320x80/ffffff/000000?text=invoice%20123&fontSize=24"
)
def test_structured_image_is_local_content_bearing_png() -> None:
png: Final = structured_image_bytes()
encoded: Final = structured_image_data_uri().partition(",")[2]
image: Final = Image.open(BytesIO(png))
colors: Final = cast(list[tuple[int, tuple[int, int, int]]], image.getcolors(maxcolors=2))
assert png.startswith(b"\x89PNG\r\n\x1a\n")
assert base64.b64decode(encoded, validate=True) == png
assert image.size == (320, 80)
assert {color for _, color in colors} == {(0, 0, 0), (255, 255, 255)}

View file

@ -0,0 +1,191 @@
from __future__ import annotations
import logging
import threading
from collections.abc import Generator
from contextlib import contextmanager
from dataclasses import dataclass
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
from typing import Final, Literal
import httpx
import pytest
from hypothesis import strategies as st
from pydantic import BaseModel, ConfigDict
from .pipeline import (
RecordingInvocation,
RecordingTarget,
build_recording_jobs,
record_fixtures,
)
from .recording import UpstreamEndpoint
from .store import fixture_path
from ..recorded_http import RecordedResponse
class _FixtureInput(BaseModel):
model_config = ConfigDict(frozen=True, extra="forbid")
identifier: str
def canonical_input(self) -> dict[str, object]:
return {"identifier": self.identifier}
class _ParityCase(BaseModel):
model_config = ConfigDict(frozen=True, extra="forbid")
litellm_input: _FixtureInput
provider_responses: tuple[RecordedResponse, ...]
class _Upstream(ThreadingHTTPServer):
daemon_threads = True
def __init__(self) -> None:
super().__init__(("127.0.0.1", 0), _UpstreamHandler)
@property
def url(self) -> str:
return f"http://127.0.0.1:{self.server_address[1]}"
class _UpstreamHandler(BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"
def do_POST(self) -> None:
length: Final = int(self.headers.get("content-length") or "0")
self.rfile.read(length)
body: Final = b"{}"
self.send_response(200)
self.send_header("content-type", "application/json")
self.send_header("content-length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, format: str, *args: object) -> None:
return
@contextmanager
def _upstream() -> Generator[_Upstream]:
server: Final = _Upstream()
thread: Final = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
try:
yield server
finally:
server.shutdown()
server.server_close()
thread.join(timeout=5)
@dataclass(frozen=True, slots=True)
class _OrderedInvocation:
order: Literal["slow", "fast"]
slow_started: threading.Event
fast_finished: threading.Event
def execute(self, provider_url: str, case_input: _FixtureInput) -> None:
if self.order == "slow":
self.slow_started.set()
if not self.fast_finished.wait(timeout=2):
raise TimeoutError("fast recording did not finish")
else:
if not self.slow_started.wait(timeout=2):
raise TimeoutError("slow recording did not start")
response: Final = httpx.post(f"{provider_url}/record", json={"id": case_input.identifier}, timeout=5)
response.raise_for_status()
if self.order == "fast":
self.fast_finished.set()
@dataclass(frozen=True, slots=True)
class _Invocation:
def execute(self, provider_url: str, case_input: _FixtureInput) -> None:
response: Final = httpx.post(f"{provider_url}/record", json={"id": case_input.identifier}, timeout=5)
response.raise_for_status()
def _target(
name: str,
upstream_url: str,
case_input: _FixtureInput,
invocation: RecordingInvocation[_FixtureInput],
) -> RecordingTarget[_FixtureInput]:
return RecordingTarget(
name=name,
upstream=UpstreamEndpoint(base_url=upstream_url),
strategy=st.just(case_input),
invocation=invocation,
required_inputs=(case_input,),
)
def test_build_jobs_keeps_required_inputs_before_generated_inputs_and_deduplicates(tmp_path: Path) -> None:
required: Final = _FixtureInput(identifier="required")
generated: Final = _FixtureInput(identifier="generated")
target: Final = RecordingTarget(
name="ordered",
upstream=UpstreamEndpoint(base_url="https://provider.invalid"),
strategy=st.just(generated),
invocation=_Invocation(),
required_inputs=(required, required),
)
jobs: Final = build_recording_jobs((target,), tmp_path, examples=1)
assert tuple(job.case_input.identifier for job in jobs) == ("required", "generated")
def test_progress_follows_completion_order(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
slow_started: Final = threading.Event()
fast_finished: Final = threading.Event()
with _upstream() as upstream:
targets: Final = (
_target(
"slow",
upstream.url,
_FixtureInput(identifier="slow"),
_OrderedInvocation("slow", slow_started, fast_finished),
),
_target(
"fast",
upstream.url,
_FixtureInput(identifier="fast"),
_OrderedInvocation("fast", slow_started, fast_finished),
),
)
with caplog.at_level(logging.INFO, logger="tests.rust-python-harness.shared.parity.fixtures.pipeline"):
summary: Final = record_fixtures(targets, tmp_path, 1, 2, _ParityCase)
progress: Final = tuple(record.message for record in caplog.records if record.message.startswith("["))
assert len(summary.recorded) == 2
assert summary.exit_code == 0
assert "recorded fast" in progress[0]
assert "recorded slow" in progress[1]
assert caplog.records[0].message == "Recording 2 fixtures across 2 targets with concurrency 2"
assert caplog.records[-1].message == "Finished 2 fixtures: 2 recorded, 0 cached, 0 failed"
def test_failure_does_not_stop_independent_recordings(tmp_path: Path) -> None:
stale_input: Final = _FixtureInput(identifier="stale")
stale_directory: Final = tmp_path / "stale"
stale_directory.mkdir()
fixture_path(stale_directory, stale_input).with_suffix(".json").write_text(
'{"schema_version": 0}\n', encoding="utf-8"
)
with _upstream() as upstream:
targets: Final = (
_target("stale", upstream.url, stale_input, _Invocation()),
_target("valid", upstream.url, _FixtureInput(identifier="valid"), _Invocation()),
)
summary: Final = record_fixtures(targets, tmp_path, 1, 2, _ParityCase)
assert len(summary.recorded) == 1
assert summary.recorded[0].target_name == "valid"
assert len(summary.failed) == 1
assert summary.failed[0].target_name == "stale"
assert summary.exit_code == 1

View file

@ -0,0 +1,574 @@
from __future__ import annotations
import asyncio
import queue
import threading
from collections.abc import AsyncIterator, Callable, Generator, Iterator
from contextlib import contextmanager
from dataclasses import dataclass
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
from typing import Final, Literal
import httpx
import pytest
from hypothesis import strategies as st
from openai._streaming import SSEDecoder
from pydantic import BaseModel, ConfigDict
from ..compare import assert_request_parity
from .pipeline import RecordingTarget, record_fixtures
from .recording import (
UpstreamEndpoint,
record_upstream_interactions,
record_upstream_responses,
)
from .store import (
FIXTURE_SCHEMA_VERSION,
fixture_path,
load_fixture,
recorded_fixtures,
)
from ..inprocess import InProcessExecution, run_in_process, run_in_process_async
from ..recorded_http import (
HttpHeader,
RecordedHttpStreamResponse,
RecordedResponse,
RecordedStreamChunk,
)
from ..replay import ReplayServer, replay_server
from ..stream import (
StreamCompleted,
StreamFailed,
StreamOutcome,
assert_stream_parity,
consume_async_stream,
consume_sync_stream,
)
_SSE_CHUNKS: Final = (
b'data: {"choices":[{"delta":{"content":"hello"}}]}\n\n',
b'data: {"choices":[{"delta":{"content":" world"}}]}\n\n',
b"data: [DONE]\n\n",
)
class _StreamEvent(BaseModel):
kind: Literal["delta", "done", "error"]
value: str
class _StreamApplicationError(Exception):
status_code: Final = 400
code: Final = "invalid_input"
type: Final = "validation_error"
param: Final = "input"
model: Final = "fixture-model"
llm_provider: Final = "fixture-provider"
def _stream_event(data: str) -> _StreamEvent:
event: Final = _StreamEvent.model_validate_json(data)
if event.kind == "error":
raise _StreamApplicationError(event.value)
return event
def _event_chunks(failed: bool) -> tuple[bytes, ...]:
terminal: Final = (
b'event: error\r\ndata: {"kind":"error","value":"invalid input"}\r\n\r\n'
if failed
else b'event: done\r\ndata: {"kind":"done","value":""}\r\n\r\n'
)
return (
b'event: delta\r\ndata: {"kind":"delta",\r\ndata: "value":"caf\xc3',
b'\xa9"}\r\n',
b'\r\nevent: delta\r\ndata: {"kind":"delta","value":"second"}\r\n\r\n' + terminal,
)
def _sync_events(api_base: str, case_input: _FixtureInput) -> Iterator[_StreamEvent]:
with httpx.stream("POST", f"{api_base}/stream", json={"id": case_input.identifier}, timeout=5) as response:
response.raise_for_status()
for event in SSEDecoder().iter_bytes(response.iter_bytes()):
yield _stream_event(event.data)
async def _async_events(api_base: str, case_input: _FixtureInput) -> AsyncIterator[_StreamEvent]:
async with httpx.AsyncClient(timeout=5) as client:
async with client.stream("POST", f"{api_base}/stream", json={"id": case_input.identifier}) as response:
response.raise_for_status()
async for event in SSEDecoder().aiter_bytes(response.aiter_bytes()):
yield _stream_event(event.data)
async def _consume_async_events(api_base: str, case_input: _FixtureInput) -> StreamOutcome:
async def create() -> AsyncIterator[_StreamEvent]:
return _async_events(api_base, case_input)
return await consume_async_stream(create)
async def _replay_events(
mode: Literal["sync", "async"],
provider: ReplayServer,
response: RecordedHttpStreamResponse,
case_input: _FixtureInput,
) -> InProcessExecution[StreamOutcome]:
if mode == "sync":
return run_in_process(
provider, (response,), lambda url: consume_sync_stream(lambda: _sync_events(url, case_input))
)
return await run_in_process_async(provider, (response,), lambda url: _consume_async_events(url, case_input))
class _FixtureInput(BaseModel):
model_config = ConfigDict(frozen=True, extra="forbid")
identifier: str
def canonical_input(self) -> dict[str, object]:
return {"identifier": self.identifier}
class _ParityCase(BaseModel):
model_config = ConfigDict(frozen=True, extra="forbid")
litellm_input: _FixtureInput
provider_responses: tuple[RecordedResponse, ...]
@dataclass(frozen=True, slots=True)
class _Invocation:
sdk_call: Callable[[str, _FixtureInput], object]
def execute(self, provider_url: str, case_input: _FixtureInput) -> None:
self.sdk_call(provider_url, case_input)
class _ControlledUpstream(ThreadingHTTPServer):
daemon_threads = True
def __init__(self, stream_chunks: tuple[bytes, ...]) -> None:
super().__init__(("127.0.0.1", 0), _ControlledUpstreamHandler)
self.stream_chunks: Final = stream_chunks
self.lock: Final = threading.Lock()
self.two_requests_started: Final = threading.Event()
self.active_requests: int = 0
self.max_active_requests: int = 0
self.request_count: int = 0
@property
def url(self) -> str:
return f"http://127.0.0.1:{self.server_address[1]}"
def start_request(self) -> None:
with self.lock:
self.active_requests += 1
self.request_count += 1
self.max_active_requests = max(self.max_active_requests, self.active_requests)
if self.active_requests == 2:
self.two_requests_started.set()
self.two_requests_started.wait(timeout=2)
def end_tracked_request(self) -> None:
with self.lock:
self.active_requests -= 1
class _ControlledUpstreamHandler(BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"
def do_POST(self) -> None:
upstream: Final = self.server
assert isinstance(upstream, _ControlledUpstream)
length: Final = int(self.headers.get("content-length") or "0")
self.rfile.read(length)
if self.path == "/credentials?api_key=query-secret&api-version=1":
authorized: Final = self.headers.get("authorization") == "Bearer header-secret"
self._send_json(200 if authorized else 401, b"{}")
return
if self.path == "/upload":
self._send_json(200, b'{"file_id":"fixture://document.pdf"}')
return
if self.path == "/parse":
self._send_json(200, b'{"result":{"chunks":[]}}')
return
if self.path == "/analyze":
self.send_response(202)
self.send_header("operation-location", f"{upstream.url}/results/1")
self.send_header("content-length", "0")
self.end_headers()
return
if self.path in {"/v1/chat/completions", "/stream"}:
with upstream.lock:
upstream.request_count += 1
self.send_response(200)
self.send_header("content-type", "text/event-stream")
self.send_header("transfer-encoding", "chunked")
self.end_headers()
for chunk in upstream.stream_chunks:
self.wfile.write(f"{len(chunk):X}\r\n".encode("ascii"))
self.wfile.write(chunk)
self.wfile.write(b"\r\n")
self.wfile.flush()
self.wfile.write(b"0\r\n\r\n")
self.wfile.flush()
return
if self.path == "/error":
self._send_json(429, b'{"error":{"message":"rate limited"}}')
return
upstream.start_request()
try:
body: Final = b"{}"
self.send_response(200)
self.send_header("content-type", "application/json")
self.send_header("set-cookie", "session=must-not-be-recorded")
self.send_header("content-length", str(len(body)))
self.end_headers()
self.wfile.write(body)
finally:
upstream.end_tracked_request()
def do_GET(self) -> None:
if self.path == "/results/1":
self._send_json(200, b'{"status":"succeeded","analyzeResult":{"pages":[]}}')
return
self.send_error(404)
def do_PUT(self) -> None:
self.do_POST()
def do_PATCH(self) -> None:
self.do_POST()
def do_DELETE(self) -> None:
self.do_POST()
def _send_json(self, status: int, body: bytes) -> None:
self.send_response(status)
self.send_header("content-type", "application/json")
self.send_header("content-length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, format: str, *args: object) -> None:
return
@contextmanager
def _controlled_upstream(stream_chunks: tuple[bytes, ...] = _SSE_CHUNKS) -> Generator[_ControlledUpstream]:
server: Final = _ControlledUpstream(stream_chunks)
thread: Final = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
try:
yield server
finally:
server.shutdown()
server.server_close()
thread.join(timeout=5)
def _case(identifier: str) -> _FixtureInput:
return _FixtureInput(identifier=identifier)
def _sdk_call(api_base: str, case_input: _FixtureInput) -> object:
return httpx.post(f"{api_base}/v1/operation", content=b"{}", timeout=5)
def _stream_sdk_call(api_base: str, case_input: _FixtureInput) -> object:
return httpx.post(f"{api_base}/v1/chat/completions", content=b"{}", timeout=5)
def _error_sdk_call(api_base: str, case_input: _FixtureInput) -> object:
response: Final = httpx.post(f"{api_base}/error", content=b"{}", timeout=5)
response.raise_for_status()
return response
def _method_sdk_call(method: str) -> Callable[[str, _FixtureInput], object]:
def call(api_base: str, case_input: _FixtureInput) -> object:
return httpx.request(method, f"{api_base}/method", json={"id": case_input.identifier}, timeout=5)
return call
def _multi_sdk_call(api_base: str, case_input: _FixtureInput) -> object:
upload: Final = httpx.post(f"{api_base}/upload", json={"document": case_input.identifier}, timeout=5)
upload.raise_for_status()
parsed: Final = httpx.post(f"{api_base}/parse", json={"input": upload.json()["file_id"]}, timeout=5)
parsed.raise_for_status()
return parsed
def _polling_sdk_call(api_base: str, case_input: _FixtureInput) -> object:
started: Final = httpx.post(f"{api_base}/analyze", json={"document": case_input.identifier}, timeout=5)
operation_location: Final = started.headers["operation-location"]
completed: Final = httpx.get(operation_location, timeout=5)
completed.raise_for_status()
return completed
def test_recording_deduplicates_per_target_and_caps_global_concurrency(tmp_path: Path) -> None:
shared_input: Final = _case("shared")
with _controlled_upstream() as upstream:
spec: Final = UpstreamEndpoint(base_url=upstream.url)
targets: Final = (
RecordingTarget(
name="first",
upstream=spec,
strategy=st.just(shared_input),
invocation=_Invocation(_sdk_call),
required_inputs=(shared_input, shared_input),
),
RecordingTarget(
name="second",
upstream=spec,
strategy=st.just(shared_input),
invocation=_Invocation(_sdk_call),
required_inputs=(shared_input,),
),
)
summary: Final = record_fixtures(targets, tmp_path, examples=1, concurrency=2, case_type=_ParityCase)
assert len(summary.recorded) == 2
assert {result.target_name for result in summary.recorded} == {"first", "second"}
assert summary.cached == ()
assert summary.failed == ()
assert upstream.request_count == 2
assert upstream.max_active_requests == 2
assert len(recorded_fixtures(tmp_path, _ParityCase)) == 2
for path in tmp_path.rglob("*.yaml"):
contents = path.read_text(encoding="utf-8")
assert f"schema_version: {FIXTURE_SCHEMA_VERSION}" in contents
assert "recorded_at:" in contents
def test_pipeline_rejects_stale_fixture_before_provider_call(tmp_path: Path) -> None:
case_input: Final = _case("stale")
directory: Final = tmp_path / "stale-target"
directory.mkdir()
path: Final = fixture_path(directory, case_input).with_suffix(".json")
path.write_text('{"schema_version": 0}\n', encoding="utf-8")
target: Final = RecordingTarget(
name="stale-target",
upstream=UpstreamEndpoint(base_url="http://127.0.0.1:1"),
strategy=st.just(case_input),
invocation=_Invocation(_sdk_call),
)
summary: Final = record_fixtures(
(target,),
tmp_path,
examples=1,
concurrency=1,
case_type=_ParityCase,
)
assert summary.recorded == ()
assert summary.cached == ()
assert len(summary.failed) == 1
assert str(summary.failed[0].error) == (
f"fixture {path} has schema_version 0, expected {FIXTURE_SCHEMA_VERSION}; "
"delete it and regenerate the fixture bundle"
)
def test_cached_fixture_is_reported_without_provider_call(tmp_path: Path) -> None:
case_input: Final = _case("cached")
with _controlled_upstream() as upstream:
target: Final = RecordingTarget(
name="cached-target",
upstream=UpstreamEndpoint(base_url=upstream.url),
strategy=st.just(case_input),
invocation=_Invocation(_sdk_call),
)
first: Final = record_fixtures((target,), tmp_path, 1, 1, _ParityCase)
second: Final = record_fixtures((target,), tmp_path, 1, 1, _ParityCase)
assert len(first.recorded) == 1
assert len(second.cached) == 1
assert upstream.request_count == 1
def test_streaming_response_records_and_replays_chunks() -> None:
with _controlled_upstream() as upstream:
responses: Final = record_upstream_responses(
UpstreamEndpoint(base_url=upstream.url),
_case("stream"),
_stream_sdk_call,
)
response: Final = responses[0]
assert isinstance(response, RecordedHttpStreamResponse)
assert tuple(chunk.data_bytes() for chunk in response.chunks) == _SSE_CHUNKS
assert isinstance(response.model_dump(mode="json")["chunks"], list)
with replay_server() as provider:
provider.enqueue_response(response)
with httpx.stream("POST", f"{provider.url}/v1/chat/completions", json={}) as replayed:
replayed_chunks: Final = tuple(replayed.iter_raw())
provider.take_requests(1)
assert replayed_chunks == _SSE_CHUNKS
def test_non_successful_provider_response_is_recorded() -> None:
with _controlled_upstream() as upstream:
responses: Final = record_upstream_responses(
UpstreamEndpoint(base_url=upstream.url),
_case("provider-error"),
_error_sdk_call,
)
response: Final = responses[0]
assert response.status_code == 429
def test_sensitive_response_headers_are_not_recorded() -> None:
with _controlled_upstream() as upstream:
responses: Final = record_upstream_responses(
UpstreamEndpoint(base_url=upstream.url),
_case("headers"),
_sdk_call,
)
assert all(header.name.lower() != "set-cookie" for header in responses[0].headers)
def test_recorded_requests_strip_credentials_without_changing_the_live_request() -> None:
def sdk_call(api_base: str, case_input: _FixtureInput) -> object:
return httpx.post(
f"{api_base}/credentials?api_key=query-secret&api-version=1",
headers={
"Authorization": "Bearer header-secret",
"Ocp-Apim-Subscription-Key": "azure-secret",
"Cookie": "session=cookie-secret",
"X-Test": case_input.identifier,
},
content=b"\xffdocument",
)
with _controlled_upstream() as upstream:
interactions: Final = record_upstream_interactions(
UpstreamEndpoint(upstream.url), _case("credentials"), sdk_call
)
interaction: Final = interactions[0]
assert interaction.response.status_code == 200
assert interaction.request.uri == "http://parity-provider.invalid/credentials?api-version=1"
assert interaction.request.body == b"\xffdocument"
assert interaction.request.headers["x-test"] == "credentials"
assert all(
header not in interaction.request.headers for header in ("authorization", "ocp-apim-subscription-key", "cookie")
)
@pytest.mark.parametrize("method", ("PUT", "PATCH", "DELETE"))
def test_recording_and_replay_support_mutating_http_methods(method: str) -> None:
sdk_call: Final = _method_sdk_call(method)
with _controlled_upstream() as upstream:
responses: Final = record_upstream_responses(
UpstreamEndpoint(base_url=upstream.url),
_case(method),
sdk_call,
)
with replay_server() as provider:
provider.enqueue_response(responses[0])
sdk_call(provider.url, _case(method))
requests: Final = provider.take_requests(1)
assert requests[0].method == method
def test_stream_response_model_rejects_buffered_body() -> None:
with pytest.raises(ValueError, match="Extra inputs are not permitted"):
RecordedHttpStreamResponse.model_validate(
{
"kind": "http_stream",
"status_code": 200,
"headers": [HttpHeader(name="content-type", value="text/event-stream")],
"chunks": [RecordedStreamChunk.from_bytes(b"data: [DONE]\n\n")],
"body_b64": "",
}
)
@pytest.mark.parametrize("sdk_call", (_multi_sdk_call, _polling_sdk_call))
def test_multiple_provider_calls_record_and_replay_in_order(
sdk_call: Callable[[str, _FixtureInput], object],
) -> None:
with _controlled_upstream() as upstream:
responses: Final = record_upstream_responses(
UpstreamEndpoint(base_url=upstream.url),
_case(sdk_call.__name__),
sdk_call,
)
assert len(responses) == 2
with replay_server() as provider:
for response in responses:
provider.enqueue_response(response)
sdk_call(provider.url, _case(sdk_call.__name__))
requests: Final = provider.take_requests(2)
assert len(requests) == 2
@pytest.mark.asyncio
@pytest.mark.parametrize("mode", ("sync", "async"))
@pytest.mark.parametrize("failed", (False, True), ids=("completed", "application-error"))
async def test_typed_stream_recording_cassette_replay_parity(
tmp_path: Path, mode: Literal["sync", "async"], failed: bool
) -> None:
case_input: Final = _case("typed-stream")
outcomes: Final[queue.SimpleQueue[StreamOutcome]] = queue.SimpleQueue()
def record(api_base: str, sdk_input: _FixtureInput) -> None:
outcome: Final = (
consume_sync_stream(lambda: _sync_events(api_base, sdk_input))
if mode == "sync"
else asyncio.run(_consume_async_events(api_base, sdk_input))
)
outcomes.put(outcome)
with _controlled_upstream(_event_chunks(failed)) as upstream:
target: Final = RecordingTarget(
name="stream",
upstream=UpstreamEndpoint(upstream.url),
strategy=st.just(case_input),
invocation=_Invocation(record),
)
summary: Final = record_fixtures((target,), tmp_path, 1, 1, _ParityCase)
assert summary.failed == ()
assert len(summary.recorded) == 1
recorded: Final = outcomes.get_nowait()
loaded: Final = load_fixture(tmp_path / "stream", case_input, _ParityCase)
assert loaded is not None
response: Final = loaded.provider_responses[0]
assert isinstance(response, RecordedHttpStreamResponse)
assert response.status_code == 200
wire_bytes: Final = b"".join(chunk.data_bytes() for chunk in response.chunks)
assert wire_bytes == b"".join(_event_chunks(failed))
coalesced: Final = response.model_copy(update={"chunks": (RecordedStreamChunk.from_bytes(wire_bytes),)})
with replay_server() as provider:
first: Final = await _replay_events(mode, provider, response, case_input)
second: Final = await _replay_events(mode, provider, coalesced, case_input)
assert_request_parity(first.requests, second.requests)
assert len(first.requests) == 1
assert first.requests[0].body == {"id": case_input.identifier}
assert_stream_parity(recorded, first.response)
assert_stream_parity(first.response, second.response)
expected: Final = (_StreamEvent(kind="delta", value="café"), _StreamEvent(kind="delta", value="second"))
assert first.response.chunks == (expected if failed else (*expected, _StreamEvent(kind="done", value="")))
if failed:
assert isinstance(first.response.terminal, StreamFailed)
assert first.response.terminal.phase == "iteration"
assert first.response.terminal.exception_type is _StreamApplicationError
assert first.response.terminal.error.code == "invalid_input"
assert first.response.terminal.error.message == "invalid input"
else:
assert first.response.terminal == StreamCompleted()

View file

@ -0,0 +1,54 @@
from __future__ import annotations
from collections.abc import Iterable
from typing import Final
HOP_BY_HOP_HEADERS: Final[frozenset[str]] = frozenset(
{
"connection",
"keep-alive",
"proxy-authenticate",
"proxy-authorization",
"te",
"trailer",
"trailers",
"transfer-encoding",
"upgrade",
}
)
REQUEST_DROPPED_HEADERS: Final[frozenset[str]] = HOP_BY_HOP_HEADERS | {
"host",
"content-length",
"accept-encoding",
}
RESPONSE_DROPPED_HEADERS: Final[frozenset[str]] = HOP_BY_HOP_HEADERS | {
"content-encoding",
"content-length",
"set-cookie",
}
def connection_header_names(headers: Iterable[tuple[str, str]]) -> frozenset[str]:
return frozenset(
token.strip().lower()
for name, value in headers
if name.lower() == "connection"
for token in value.split(",")
if token.strip()
)
def dropped_request_headers(headers: Iterable[tuple[str, str]]) -> frozenset[str]:
materialized: Final = tuple(headers)
return REQUEST_DROPPED_HEADERS | connection_header_names(materialized)
def dropped_response_headers(headers: Iterable[tuple[str, str]]) -> frozenset[str]:
materialized: Final = tuple(headers)
return RESPONSE_DROPPED_HEADERS | connection_header_names(materialized)
def is_streaming_response(content_type: str) -> bool:
return "text/event-stream" in content_type.lower()

View file

@ -0,0 +1,47 @@
from __future__ import annotations
from collections.abc import Awaitable, Callable
from dataclasses import dataclass
from typing import Final, Generic, TypeVar
from .models import CapturedRequest
from .recorded_http import RecordedResponse
from .replay import ReplayServer
ResponseT = TypeVar("ResponseT")
@dataclass(frozen=True, slots=True)
class InProcessExecution(Generic[ResponseT]):
requests: tuple[CapturedRequest, ...]
response: ResponseT
def run_in_process(
provider: ReplayServer,
recorded_responses: tuple[RecordedResponse, ...],
call: Callable[[str], ResponseT],
) -> InProcessExecution[ResponseT]:
for recorded_response in recorded_responses:
provider.enqueue_response(recorded_response)
try:
response: Final = call(provider.url)
return InProcessExecution(requests=provider.take_requests(len(recorded_responses)), response=response)
except Exception:
provider.reset()
raise
async def run_in_process_async(
provider: ReplayServer,
recorded_responses: tuple[RecordedResponse, ...],
call: Callable[[str], Awaitable[ResponseT]],
) -> InProcessExecution[ResponseT]:
for recorded_response in recorded_responses:
provider.enqueue_response(recorded_response)
try:
response: Final = await call(provider.url)
return InProcessExecution(requests=provider.take_requests(len(recorded_responses)), response=response)
except Exception:
provider.reset()
raise

View file

@ -0,0 +1,145 @@
from __future__ import annotations
import base64
from typing import Annotated, Final, Literal, cast
from pydantic import BaseModel, ConfigDict, Field, JsonValue, TypeAdapter
class CapturedRequest(BaseModel):
model_config = ConfigDict(frozen=True)
method: str
path: str
headers: tuple[tuple[str, str], ...]
body: JsonValue
user_agent: str | None
class SDKSuccess(BaseModel):
model_config = ConfigDict(frozen=True)
status: Literal["ok"] = "ok"
response: JsonValue
class SDKError(BaseModel):
model_config = ConfigDict(frozen=True)
status: Literal["error"] = "error"
exception_type: str
message: str
status_code: int | None
code: str | None
error_type: str | None
param: str | None
model: str | None
llm_provider: str | None
class SDKJsonChunk(BaseModel):
model_config = ConfigDict(frozen=True)
kind: Literal["json"] = "json"
value: JsonValue
class SDKBytesChunk(BaseModel):
model_config = ConfigDict(frozen=True)
kind: Literal["bytes"] = "bytes"
data_b64: str
def data_bytes(self) -> bytes:
return base64.b64decode(self.data_b64, validate=True)
SDKChunk = Annotated[SDKJsonChunk | SDKBytesChunk, Field(discriminator="kind")]
class SDKStreamCompleted(BaseModel):
model_config = ConfigDict(frozen=True)
kind: Literal["completed"] = "completed"
class SDKStreamFailed(BaseModel):
model_config = ConfigDict(frozen=True)
kind: Literal["failed"] = "failed"
error: SDKError
SDKStreamTerminal = Annotated[SDKStreamCompleted | SDKStreamFailed, Field(discriminator="kind")]
class SDKStreamReport(BaseModel):
model_config = ConfigDict(frozen=True)
status: Literal["stream"] = "stream"
chunks: tuple[SDKChunk, ...]
terminal: SDKStreamTerminal
SDKReport = Annotated[SDKSuccess | SDKError | SDKStreamReport, Field(discriminator="status")]
JSON_VALUE_ADAPTER: Final[TypeAdapter[JsonValue]] = TypeAdapter(JsonValue)
def sdk_chunk(value: object) -> SDKChunk:
if isinstance(value, bytes):
return SDKBytesChunk(data_b64=base64.b64encode(value).decode("ascii"))
if isinstance(value, BaseModel):
return SDKJsonChunk(value=JSON_VALUE_ADAPTER.validate_python(value.model_dump(mode="json")))
return SDKJsonChunk(value=JSON_VALUE_ADAPTER.validate_python(value))
def _string_attribute(error: Exception, name: str) -> str | None:
value: Final = cast(object | None, getattr(error, name, None))
return None if value is None else str(value)
def sdk_error_report(error: Exception) -> SDKError:
message, _, _ = str(error).partition("\nTraceback (most recent call last):")
raw_status_code: Final = cast(object | None, getattr(error, "status_code", None))
status_code: Final = raw_status_code if isinstance(raw_status_code, int) else None
return SDKError(
exception_type=f"{type(error).__module__}.{type(error).__qualname__}",
message=message.rstrip(),
status_code=status_code,
code=_string_attribute(error, "code"),
error_type=_string_attribute(error, "type"),
param=_string_attribute(error, "param"),
model=_string_attribute(error, "model"),
llm_provider=_string_attribute(error, "llm_provider"),
)
class Execution(BaseModel):
model_config = ConfigDict(frozen=True)
requests: tuple[CapturedRequest, ...]
report: SDKReport
class SDKCommand(BaseModel):
model_config = ConfigDict(frozen=True)
case_file: str
route: str
class WorkerSuccess(BaseModel):
model_config = ConfigDict(frozen=True)
status: Literal["ok"] = "ok"
report: SDKReport
class WorkerFailure(BaseModel):
model_config = ConfigDict(frozen=True)
status: Literal["error"] = "error"
error: str
WorkerResult = Annotated[WorkerSuccess | WorkerFailure, Field(discriminator="status")]

View file

@ -0,0 +1,63 @@
from __future__ import annotations
import base64
from typing import Annotated, Literal
from pydantic import BaseModel, ConfigDict, Field
class _RecordedHttpModel(BaseModel):
model_config = ConfigDict(frozen=True, extra="forbid")
class HttpHeader(_RecordedHttpModel):
name: str
value: str
class RecordedHttpResponse(_RecordedHttpModel):
kind: Literal["http"]
status_code: int
headers: tuple[HttpHeader, ...]
body_b64: str
@classmethod
def from_bytes(
cls,
status_code: int,
headers: tuple[HttpHeader, ...],
body: bytes,
) -> RecordedHttpResponse:
return cls(
kind="http",
status_code=status_code,
headers=headers,
body_b64=base64.b64encode(body).decode("ascii"),
)
def body_bytes(self) -> bytes:
return base64.b64decode(self.body_b64, validate=True)
class RecordedStreamChunk(_RecordedHttpModel):
data_b64: str
@classmethod
def from_bytes(cls, data: bytes) -> RecordedStreamChunk:
return cls(data_b64=base64.b64encode(data).decode("ascii"))
def data_bytes(self) -> bytes:
return base64.b64decode(self.data_b64, validate=True)
class RecordedHttpStreamResponse(_RecordedHttpModel):
kind: Literal["http_stream"]
status_code: int
headers: tuple[HttpHeader, ...]
chunks: tuple[RecordedStreamChunk, ...]
RecordedResponse = Annotated[
RecordedHttpResponse | RecordedHttpStreamResponse,
Field(discriminator="kind"),
]

View file

@ -0,0 +1,147 @@
from __future__ import annotations
import base64
import queue
import threading
from collections.abc import Generator
from contextlib import contextmanager
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from typing import Final
from pydantic import JsonValue, TypeAdapter
from .fixtures.recording import local_response_header
from .models import CapturedRequest
from .recorded_http import RecordedHttpResponse, RecordedHttpStreamResponse, RecordedResponse
JSON_VALUE: Final[TypeAdapter[JsonValue]] = TypeAdapter(JsonValue)
EXCLUDED_REQUEST_HEADERS: Final = frozenset(
{
"host",
"content-length",
"connection",
"accept-encoding",
"user-agent",
"x-litellm-parity-route",
}
)
EXCLUDED_RESPONSE_HEADERS: Final = frozenset({"content-length", "transfer-encoding", "connection"})
class ReplayServer(ThreadingHTTPServer):
daemon_threads = True
def __init__(self) -> None:
super().__init__(("127.0.0.1", 0), _ReplayHandler)
self.responses: queue.Queue[RecordedResponse] = queue.Queue()
self.requests: queue.Queue[CapturedRequest] = queue.Queue()
@property
def url(self) -> str:
return f"http://127.0.0.1:{self.server_address[1]}"
def enqueue_response(self, response: RecordedResponse) -> None:
self.responses.put(response)
def take_requests(self, expected_count: int) -> tuple[CapturedRequest, ...]:
request_count: Final = self.requests.qsize()
if request_count != expected_count:
raise AssertionError(f"expected exactly {expected_count} provider requests, received {request_count}")
return tuple(self.requests.get_nowait() for _ in range(request_count))
def reset(self) -> None:
while not self.responses.empty():
self.responses.get_nowait()
while not self.requests.empty():
self.requests.get_nowait()
class _ReplayHandler(BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"
def do_POST(self) -> None:
self._replay()
def do_GET(self) -> None:
self._replay()
def do_PUT(self) -> None:
self._replay()
def do_PATCH(self) -> None:
self._replay()
def do_DELETE(self) -> None:
self._replay()
def _replay(self) -> None:
provider: Final = self.server
assert isinstance(provider, ReplayServer)
length: Final = int(self.headers.get("content-length") or "0")
raw_body: Final = self.rfile.read(length) if length else b""
content_type: Final = self.headers.get("content-type", "")
body: Final = (
JSON_VALUE.validate_json(raw_body)
if raw_body and content_type.lower().startswith("application/json")
else base64.b64encode(raw_body).decode("ascii")
if raw_body
else None
)
headers: Final = tuple(
sorted(
(name.lower(), value)
for name, value in self.headers.raw_items()
if name.lower() not in EXCLUDED_REQUEST_HEADERS
)
)
provider.requests.put(
CapturedRequest(
method=self.command,
path=self.path,
headers=headers,
body=body,
user_agent=self.headers.get("user-agent"),
)
)
try:
response: Final = provider.responses.get(timeout=5)
except queue.Empty:
self.send_error(500, "no replay response queued")
return
self.send_response_only(response.status_code)
for header in response.headers:
if header.name.lower() not in EXCLUDED_RESPONSE_HEADERS:
self.send_header(header.name, local_response_header(header.name, header.value, provider.url))
if isinstance(response, RecordedHttpResponse):
response_body: Final = response.body_bytes()
self.send_header("content-length", str(len(response_body)))
self.end_headers()
self.wfile.write(response_body)
return
assert isinstance(response, RecordedHttpStreamResponse)
self.send_header("transfer-encoding", "chunked")
self.end_headers()
for chunk in response.chunks:
data = chunk.data_bytes()
self.wfile.write(f"{len(data):X}\r\n".encode("ascii"))
self.wfile.write(data)
self.wfile.write(b"\r\n")
self.wfile.flush()
self.wfile.write(b"0\r\n\r\n")
self.wfile.flush()
def log_message(self, format: str, *args: object) -> None:
return
@contextmanager
def replay_server() -> Generator[ReplayServer]:
server: Final = ReplayServer()
thread: Final = threading.Thread(target=server.serve_forever, kwargs={"poll_interval": 0.01}, daemon=True)
thread.start()
try:
yield server
finally:
server.shutdown()
server.server_close()
thread.join(timeout=5)

View file

@ -0,0 +1,198 @@
from __future__ import annotations
import asyncio
import os
import subprocess
import sys
from collections import deque
from collections.abc import Callable, Generator
from concurrent.futures import ThreadPoolExecutor, TimeoutError
from contextlib import contextmanager
from dataclasses import dataclass
from pathlib import Path
from typing import Final, TextIO, cast
from pydantic import TypeAdapter, ValidationError
from .models import (
Execution,
SDKCommand,
WorkerFailure,
WorkerResult,
WorkerSuccess,
)
from .recorded_http import RecordedResponse
from .replay import ReplayServer, replay_server
WORKER_RESULT_PREFIX: Final = "LITELLM_PARITY_RESULT "
WORKER_RESULT_ADAPTER: Final[TypeAdapter[WorkerResult]] = TypeAdapter(WorkerResult)
@dataclass(frozen=True, slots=True)
class SubprocessRunner:
entrypoint: Path
baseline_user_agent: str
route_label: str
def command(self, provider_url: str) -> tuple[str, ...]:
return (
sys.executable,
"-m",
".".join(
self.entrypoint.resolve().relative_to(Path(__file__).resolve().parents[4]).with_suffix("").parts
),
"--parity-worker",
provider_url,
)
@dataclass(frozen=True, slots=True)
class ExecutionVariant:
name: str
environment: tuple[tuple[str, str], ...]
class SubprocessWorker:
def __init__(self, runner: SubprocessRunner, provider: ReplayServer, variant: ExecutionVariant) -> None:
project_root: Final = str(Path(__file__).resolve().parents[4])
existing_pythonpath: Final = os.environ.get("PYTHONPATH")
env: Final = {
**os.environ,
**dict(variant.environment),
"LITELLM_USER_AGENT": runner.baseline_user_agent,
"PYTHONPATH": os.pathsep.join(path for path in (project_root, existing_pythonpath) if path),
}
self.mode: Final = variant.name
self.route_label: Final = runner.route_label
self.provider: Final = provider
self.process: Final = subprocess.Popen(
runner.command(provider.url),
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1,
env=env,
)
self.output_reader: Final = ThreadPoolExecutor(max_workers=1)
self.recent_output: Final[deque[str]] = deque(maxlen=100)
def execute(
self,
case_file: Path,
route: str,
responses: tuple[RecordedResponse, ...],
) -> Execution:
stdin: Final = self.process.stdin
if stdin is None or self.process.poll() is not None:
raise AssertionError(f"{self.mode} {self.route_label} worker exited before processing {case_file}")
for response in responses:
self.provider.enqueue_response(response)
command: Final = SDKCommand(case_file=str(case_file), route=route)
try:
stdin.write(f"{command.model_dump_json()}\n")
stdin.flush()
result: Final = self.output_reader.submit(self._read_result).result(timeout=60)
except TimeoutError as error:
self.provider.reset()
self.close()
raise AssertionError(
f"{self.mode} {self.route_label} worker timed out after 60s while processing {case_file}"
) from error
except AssertionError:
self.provider.reset()
raise
except (BrokenPipeError, OSError) as error:
self.provider.reset()
raise AssertionError(self._failure_message(f"worker pipe failed while processing {case_file}")) from error
if isinstance(result, WorkerFailure):
self.provider.reset()
raise AssertionError(
f"{self.mode} {self.route_label} worker failed while processing {case_file}:\n{result.error}"
)
assert isinstance(result, WorkerSuccess)
try:
return Execution(requests=self.provider.take_requests(len(responses)), report=result.report)
except AssertionError:
self.provider.reset()
raise
def _read_result(self) -> WorkerResult:
process_stdout: Final = self.process.stdout
if process_stdout is None:
raise AssertionError(self._failure_message("worker stdout is unavailable"))
stdout: Final = cast(TextIO, process_stdout)
line: Final = stdout.readline()
if not line:
raise AssertionError(self._failure_message("worker exited without returning a result"))
stripped: Final = line.rstrip()
if not stripped.startswith(WORKER_RESULT_PREFIX):
self.recent_output.append(stripped)
return self._read_result()
payload: Final = stripped.removeprefix(WORKER_RESULT_PREFIX)
try:
return WORKER_RESULT_ADAPTER.validate_json(payload)
except ValidationError as error:
raise AssertionError(self._failure_message("worker returned an invalid result")) from error
def _failure_message(self, message: str) -> str:
output: Final = "\n".join(self.recent_output)
prefix: Final = f"{self.mode} {self.route_label}"
return f"{prefix} {message}" if not output else f"{prefix} {message}\noutput:\n{output}"
def close(self) -> None:
stdin: Final = self.process.stdin
if stdin is not None and not stdin.closed:
stdin.close()
try:
self.process.wait(timeout=10)
except subprocess.TimeoutExpired:
self.process.terminate()
self.process.wait(timeout=10)
self.output_reader.shutdown(wait=True, cancel_futures=True)
@contextmanager
def execution_worker(
runner: SubprocessRunner,
variant: ExecutionVariant,
) -> Generator[SubprocessWorker]:
with replay_server() as provider:
worker: Final = SubprocessWorker(runner, provider, variant)
try:
yield worker
finally:
worker.close()
def run_execution(
worker: SubprocessWorker,
case_file: Path,
route: str,
responses: tuple[RecordedResponse, ...],
) -> Execution:
return worker.execute(case_file, route, responses)
@contextmanager
def execution_worker_pair(
runner: SubprocessRunner,
baseline: ExecutionVariant,
candidate: ExecutionVariant,
) -> Generator[tuple[SubprocessWorker, SubprocessWorker]]:
with execution_worker(runner, baseline) as baseline_worker:
with execution_worker(runner, candidate) as candidate_worker:
yield baseline_worker, candidate_worker
def parity_worker_main(
execute_command: Callable[[str, str, asyncio.AbstractEventLoop], WorkerResult],
mock_url: str,
) -> None:
event_loop: Final = asyncio.new_event_loop()
try:
for line in sys.stdin:
sys.stdout.write(f"{WORKER_RESULT_PREFIX}{execute_command(line, mock_url, event_loop).model_dump_json()}\n")
sys.stdout.flush()
finally:
event_loop.close()

View file

@ -0,0 +1,177 @@
from __future__ import annotations
from collections.abc import AsyncIterable, Awaitable, Callable, Iterable
from dataclasses import dataclass
from typing import Final, Literal, TypeAlias
from .compare import assert_value_parity
from .models import (
SDKError,
SDKReport,
SDKStreamCompleted,
SDKStreamFailed,
SDKStreamReport,
sdk_chunk,
sdk_error_report,
)
@dataclass(frozen=True, slots=True)
class StreamCompleted:
kind: Literal["completed"] = "completed"
@dataclass(frozen=True, slots=True)
class StreamFailed:
phase: Literal["creation", "iteration"]
exception_type: type[BaseException]
error: SDKError
kind: Literal["failed"] = "failed"
StreamTerminal: TypeAlias = StreamCompleted | StreamFailed
@dataclass(frozen=True, slots=True)
class StreamOutcome:
wrapper_type: type[object] | None
supports_sync_iteration: bool | None
supports_async_iteration: bool | None
chunks: tuple[object, ...]
chunk_types: tuple[type[object], ...]
terminal: StreamTerminal
ChunkNormalizer: TypeAlias = Callable[[object], object]
def drain_sync_stream(stream: Iterable[object]) -> None:
for _ in stream:
pass
async def drain_async_stream(stream: AsyncIterable[object]) -> None:
async for _ in stream:
pass
def capture_sync_stream(create: Callable[[], Iterable[object]]) -> SDKReport:
return _stream_report(consume_sync_stream(create))
async def capture_async_stream(create: Callable[[], Awaitable[AsyncIterable[object]]]) -> SDKReport:
return _stream_report(await consume_async_stream(create))
def _stream_report(outcome: StreamOutcome) -> SDKReport:
terminal: Final = outcome.terminal
if isinstance(terminal, StreamFailed) and terminal.phase == "creation":
return terminal.error
return SDKStreamReport(
chunks=tuple(sdk_chunk(chunk) for chunk in outcome.chunks),
terminal=SDKStreamFailed(error=terminal.error) if isinstance(terminal, StreamFailed) else SDKStreamCompleted(),
)
def _failed(phase: Literal["creation", "iteration"], error: Exception) -> StreamFailed:
return StreamFailed(
phase=phase,
exception_type=type(error),
error=sdk_error_report(error),
)
def consume_sync_stream(create: Callable[[], Iterable[object]]) -> StreamOutcome:
try:
stream: Final = create()
except Exception as error:
return StreamOutcome(
wrapper_type=None,
supports_sync_iteration=None,
supports_async_iteration=None,
chunks=(),
chunk_types=(),
terminal=_failed("creation", error),
)
chunks: list[object] = [] # mutable-ok: iterator consumption builds an ordered trace
try:
for chunk in stream:
chunks.append(chunk) # noqa: PERF402 # partial trace is required if iteration raises
except Exception as error:
recorded: Final = tuple(chunks)
return StreamOutcome(
wrapper_type=type(stream),
supports_sync_iteration=hasattr(stream, "__iter__"),
supports_async_iteration=hasattr(stream, "__aiter__"),
chunks=recorded,
chunk_types=tuple(type(chunk) for chunk in recorded),
terminal=_failed("iteration", error),
)
completed_chunks: Final = tuple(chunks)
return StreamOutcome(
wrapper_type=type(stream),
supports_sync_iteration=hasattr(stream, "__iter__"),
supports_async_iteration=hasattr(stream, "__aiter__"),
chunks=completed_chunks,
chunk_types=tuple(type(chunk) for chunk in completed_chunks),
terminal=StreamCompleted(),
)
async def consume_async_stream(create: Callable[[], Awaitable[AsyncIterable[object]]]) -> StreamOutcome:
try:
stream: Final = await create()
except Exception as error:
return StreamOutcome(
wrapper_type=None,
supports_sync_iteration=None,
supports_async_iteration=None,
chunks=(),
chunk_types=(),
terminal=_failed("creation", error),
)
chunks: list[object] = [] # mutable-ok: iterator consumption builds an ordered trace
try:
async for chunk in stream:
chunks.append(chunk)
except Exception as error:
recorded: Final = tuple(chunks)
return StreamOutcome(
wrapper_type=type(stream),
supports_sync_iteration=hasattr(stream, "__iter__"),
supports_async_iteration=hasattr(stream, "__aiter__"),
chunks=recorded,
chunk_types=tuple(type(chunk) for chunk in recorded),
terminal=_failed("iteration", error),
)
completed_chunks: Final = tuple(chunks)
return StreamOutcome(
wrapper_type=type(stream),
supports_sync_iteration=hasattr(stream, "__iter__"),
supports_async_iteration=hasattr(stream, "__aiter__"),
chunks=completed_chunks,
chunk_types=tuple(type(chunk) for chunk in completed_chunks),
terminal=StreamCompleted(),
)
def normalize_chunk(chunk: object) -> object:
return chunk
def assert_stream_parity(
baseline: StreamOutcome,
candidate: StreamOutcome,
*,
normalize: ChunkNormalizer = normalize_chunk,
) -> None:
assert baseline.wrapper_type is candidate.wrapper_type
assert baseline.supports_sync_iteration is candidate.supports_sync_iteration
assert baseline.supports_async_iteration is candidate.supports_async_iteration
assert baseline.chunk_types == candidate.chunk_types
assert len(baseline.chunks) == len(candidate.chunks)
for index, (baseline_chunk, candidate_chunk) in enumerate(zip(baseline.chunks, candidate.chunks, strict=True)):
assert_value_parity(normalize(baseline_chunk), normalize(candidate_chunk), path=f"$.chunks[{index}]")
assert baseline.terminal == candidate.terminal

View file

@ -0,0 +1,190 @@
from __future__ import annotations
from types import MappingProxyType
from typing import Final
import pytest
from pydantic import BaseModel, ConfigDict, JsonValue, PrivateAttr
from .compare import assert_model_parity, assert_parity
from .models import CapturedRequest, Execution, SDKError, SDKSuccess, sdk_error_report
SENTINEL: Final = "python-parity-fallback"
class _ComparableResponse(BaseModel):
value: str
_hidden_params: dict[str, object] = PrivateAttr(default_factory=dict)
def set_hidden_param(self, key: str, value: object) -> None:
self._hidden_params[key] = value
class _DifferentResponse(BaseModel):
value: str
class _FloatResponse(BaseModel):
values: list[float]
class _PublicValue(BaseModel):
model_config = ConfigDict(extra="allow")
value: object
class _PublicError(ValueError):
status_code: Final = 400
def _execution(*, body: JsonValue = None, markdown: str = "same", user_agent: str | None = None) -> Execution:
return Execution(
requests=(
CapturedRequest(
method="POST",
path="/v1/test-route?mode=test",
headers=(("authorization", "Bearer test-key"), ("content-type", "application/json")),
body={"model": "test-model"} if body is None else body,
user_agent=user_agent,
),
),
report=SDKSuccess(response={"items": [{"text": markdown}], "model": "test-model"}),
)
def test_parity_rejects_request_difference() -> None:
python: Final = _execution(user_agent=SENTINEL)
rust: Final = _execution(body={"model": "different"}, user_agent="litellm-rust")
with pytest.raises(AssertionError):
assert_parity(python, rust, SENTINEL)
def test_parity_rejects_response_difference() -> None:
python: Final = _execution(user_agent=SENTINEL)
rust: Final = _execution(markdown="different", user_agent="litellm-rust")
with pytest.raises(AssertionError):
assert_parity(python, rust, SENTINEL)
def test_parity_rejects_error_difference() -> None:
python: Final = Execution(
requests=(),
report=SDKError(
exception_type="litellm.exceptions.BadRequestError",
message="bad request",
status_code=400,
code=None,
error_type=None,
param=None,
model="test-model",
llm_provider="test-provider",
),
)
rust: Final = python.model_copy(update={"report": python.report.model_copy(update={"status_code": 500})})
with pytest.raises(AssertionError):
assert_parity(python, rust, SENTINEL)
def test_sdk_error_report_removes_traceback_but_keeps_public_fields() -> None:
error: Final = _PublicError("invalid input\nTraceback (most recent call last):\n unstable")
report: Final = sdk_error_report(error)
assert report.exception_type.endswith("._PublicError")
assert report.message == "invalid input"
assert report.status_code == 400
def test_parity_rejects_rust_fallback() -> None:
python: Final = _execution(user_agent=SENTINEL)
rust: Final = _execution(user_agent=SENTINEL)
with pytest.raises(AssertionError, match="fell back"):
assert_parity(python, rust, SENTINEL)
def test_model_parity_compares_public_values_and_ignores_private_attrs() -> None:
python: Final = _ComparableResponse(value="same")
rust: Final = _ComparableResponse(value="same")
python.set_hidden_param("litellm_call_id", "python-id")
rust.set_hidden_param("litellm_call_id", "rust-id")
assert_model_parity(python, rust)
def test_model_parity_rejects_public_value_difference() -> None:
python: Final = _ComparableResponse(value="python")
rust: Final = _ComparableResponse(value="rust")
with pytest.raises(AssertionError):
assert_model_parity(python, rust)
def test_model_parity_rejects_type_difference() -> None:
with pytest.raises(AssertionError):
assert_model_parity(_ComparableResponse(value="same"), _DifferentResponse(value="same"))
def test_model_parity_rejects_wire_float_rounding_difference() -> None:
with pytest.raises(AssertionError, match=r"\$\.values\[0\]"):
assert_model_parity(
_FloatResponse(values=[0.22590550796036835]),
_FloatResponse(values=[0.22590550796036837]),
)
def test_model_parity_rejects_meaningful_float_difference() -> None:
with pytest.raises(AssertionError, match=r"\$\.values\[0\]"):
assert_model_parity(
_FloatResponse(values=[0.22590550796036835]),
_FloatResponse(values=[0.2259]),
)
@pytest.mark.parametrize(
("baseline", "candidate"),
(
(_ComparableResponse(value="same"), {"value": "same"}),
(_ComparableResponse(value="same"), _DifferentResponse(value="same")),
(True, 1),
(1, 1.0),
(["same"], ("same",)),
({"value": "same"}, MappingProxyType({"value": "same"})),
({True: "same"}, {1: "same"}),
),
ids=("model-dict", "model-class", "bool-int", "int-float", "list-tuple", "mapping-class", "key-type"),
)
def test_model_parity_rejects_nested_type_changes(baseline: object, candidate: object) -> None:
with pytest.raises(AssertionError, match=r"\$\.value\[0\]"):
assert_model_parity(_PublicValue(value=[baseline]), _PublicValue(value=[candidate]))
def test_model_parity_ignores_nested_private_attributes() -> None:
baseline: Final = _ComparableResponse(value="same")
candidate: Final = _ComparableResponse(value="same")
baseline.set_hidden_param("request_id", "baseline")
candidate.set_hidden_param("request_id", "candidate")
assert_model_parity(_PublicValue(value={"nested": [baseline]}), _PublicValue(value={"nested": [candidate]}))
@pytest.mark.parametrize("extras", ({"provider_value": "changed"}, {}, {"provider_value": {"value": "same"}}))
def test_model_parity_compares_public_extras(extras: dict[str, object]) -> None:
baseline: Final = _PublicValue.model_validate({"value": None, "provider_value": _ComparableResponse(value="same")})
candidate: Final = _PublicValue.model_validate({"value": None, **extras})
with pytest.raises(AssertionError):
assert_model_parity(baseline, candidate)
def test_serialized_parity_rejects_boolean_integer_substitution() -> None:
with pytest.raises(AssertionError, match="type mismatch"):
assert_parity(
_execution(body={"enabled": True}, user_agent=SENTINEL),
_execution(body={"enabled": 1}, user_agent="candidate"),
SENTINEL,
)

View file

@ -0,0 +1,344 @@
from __future__ import annotations
import queue
from collections.abc import AsyncIterator, Iterator
from typing import Final, Literal, NoReturn
import pytest
from pydantic import BaseModel, PrivateAttr, ValidationError
from .models import (
SDKBytesChunk,
SDKError,
SDKJsonChunk,
SDKReport,
SDKStreamCompleted,
SDKStreamFailed,
SDKStreamReport,
sdk_error_report,
)
from .stream import (
StreamCompleted,
StreamFailed,
StreamOutcome,
assert_stream_parity,
capture_async_stream,
capture_sync_stream,
consume_async_stream,
consume_sync_stream,
drain_async_stream,
drain_sync_stream,
)
class _Chunk(BaseModel):
value: str
_hidden_params: dict[str, object] = PrivateAttr(default_factory=dict)
def set_hidden_param(self, key: str, value: object) -> None:
self._hidden_params[key] = value
class _NestedChunk(BaseModel):
value: object
class _SyncStream:
def __init__(self, chunks: tuple[object, ...], error: BaseException | None = None) -> None:
self.chunks: Final = chunks
self.error: Final = error
def __iter__(self) -> Iterator[object]:
yield from self.chunks
if self.error is not None:
raise self.error
class _AsyncStream:
def __init__(self, chunks: tuple[object, ...], error: BaseException | None = None) -> None:
self.chunks: Final = chunks
self.error: Final = error
async def __aiter__(self) -> AsyncIterator[object]:
for chunk in self.chunks:
yield chunk
if self.error is not None:
raise self.error
class _PublicStreamError(Exception):
def __init__(
self,
message: str = "invalid input",
*,
status_code: int = 400,
llm_provider: str = "test",
model: str = "test-model",
code: str = "invalid_input",
error_type: str = "validation_error",
param: str = "input",
) -> None:
super().__init__(message)
self.status_code: Final = status_code
self.llm_provider: Final = llm_provider
self.model: Final = model
self.code: Final = code
self.type: Final = error_type
self.param: Final = param
def _creation_error() -> NoReturn:
raise _PublicStreamError(status_code=429, llm_provider="test", model="test-model")
async def _async_stream(chunks: tuple[object, ...], error: BaseException | None = None) -> _AsyncStream:
return _AsyncStream(chunks, error)
async def _consume(
mode: Literal["sync", "async"], chunks: tuple[object, ...], error: Exception | None = None
) -> StreamOutcome:
if mode == "sync":
return consume_sync_stream(lambda: _SyncStream(chunks, error))
return await consume_async_stream(lambda: _async_stream(chunks, error))
async def _capture(
mode: Literal["sync", "async"], chunks: tuple[object, ...], error: Exception | None = None
) -> SDKReport:
if mode == "sync":
return capture_sync_stream(lambda: _SyncStream(chunks, error))
return await capture_async_stream(lambda: _async_stream(chunks, error))
def test_sync_stream_parity_compares_chunks_and_ignores_private_attrs() -> None:
python_chunk: Final = _Chunk(value="same")
accelerated_chunk: Final = _Chunk(value="same")
python_chunk.set_hidden_param("request_id", "python")
accelerated_chunk.set_hidden_param("request_id", "accelerated")
python: Final = consume_sync_stream(lambda: _SyncStream((python_chunk,)))
accelerated: Final = consume_sync_stream(lambda: _SyncStream((accelerated_chunk,)))
assert python.supports_sync_iteration is True
assert python.supports_async_iteration is False
assert_stream_parity(python, accelerated)
def test_stream_parity_rejects_extra_chunk() -> None:
python: Final = consume_sync_stream(lambda: _SyncStream((_Chunk(value="one"),)))
accelerated: Final = consume_sync_stream(lambda: _SyncStream((_Chunk(value="one"), _Chunk(value="two"))))
with pytest.raises(AssertionError):
assert_stream_parity(python, accelerated)
def test_stream_parity_rejects_chunk_value_difference() -> None:
python: Final = consume_sync_stream(lambda: _SyncStream((_Chunk(value="python"),)))
accelerated: Final = consume_sync_stream(lambda: _SyncStream((_Chunk(value="accelerated"),)))
with pytest.raises(AssertionError):
assert_stream_parity(python, accelerated)
def test_stream_outcome_distinguishes_creation_and_iteration_errors() -> None:
creation: Final = consume_sync_stream(_creation_error)
iteration: Final = consume_sync_stream(
lambda: _SyncStream(
(_Chunk(value="before-error"),),
_PublicStreamError(status_code=429, llm_provider="test", model="test-model"),
)
)
assert isinstance(creation.terminal, StreamFailed)
assert creation.terminal.phase == "creation"
assert creation.chunks == ()
assert isinstance(iteration.terminal, StreamFailed)
assert iteration.terminal.phase == "iteration"
assert len(iteration.chunks) == 1
with pytest.raises(AssertionError):
assert_stream_parity(creation, iteration)
@pytest.mark.asyncio
async def test_async_stream_uses_same_trace_contract() -> None:
python_error: Final = _PublicStreamError(
"invalid input\nTraceback (most recent call last):\npython detail", status_code=500
)
accelerated_error: Final = _PublicStreamError(
"invalid input\nTraceback (most recent call last):\nrust detail", status_code=500
)
python: Final = await consume_async_stream(lambda: _async_stream((_Chunk(value="same"),), python_error))
accelerated: Final = await consume_async_stream(lambda: _async_stream((_Chunk(value="same"),), accelerated_error))
assert python.supports_sync_iteration is False
assert python.supports_async_iteration is True
assert_stream_parity(python, accelerated)
def test_stream_parity_accepts_route_specific_chunk_normalizer() -> None:
python: Final = consume_sync_stream(lambda: _SyncStream((_Chunk(value="python-generated-id"),)))
accelerated: Final = consume_sync_stream(lambda: _SyncStream((_Chunk(value="rust-generated-id"),)))
assert_stream_parity(python, accelerated, normalize=lambda chunk: type(chunk))
def test_drain_sync_stream_exhausts_lazy_iterator() -> None:
consumed: Final[queue.SimpleQueue[str]] = queue.SimpleQueue()
def chunks() -> Iterator[object]:
yield _Chunk(value="one")
consumed.put("complete")
drain_sync_stream(chunks())
assert consumed.get_nowait() == "complete"
@pytest.mark.asyncio
async def test_drain_async_stream_exhausts_lazy_iterator() -> None:
consumed: Final[queue.SimpleQueue[str]] = queue.SimpleQueue()
async def chunks() -> AsyncIterator[object]:
yield b"one"
consumed.put("complete")
await drain_async_stream(chunks())
assert consumed.get_nowait() == "complete"
def test_capture_sync_stream_serializes_model_chunks_and_partial_failure() -> None:
report: Final = capture_sync_stream(
lambda: _SyncStream(
(_Chunk(value="before-error"),),
_PublicStreamError(status_code=429, llm_provider="test", model="test-model"),
)
)
assert isinstance(report, SDKStreamReport)
assert len(report.chunks) == 1
chunk: Final = report.chunks[0]
assert isinstance(chunk, SDKJsonChunk)
assert chunk.value == {"value": "before-error"}
assert isinstance(report.terminal, SDKStreamFailed)
assert report.terminal.error.status_code == 429
@pytest.mark.asyncio
async def test_capture_async_stream_serializes_message_bytes_in_order() -> None:
report: Final = await capture_async_stream(lambda: _async_stream((b"first", b"second")))
assert isinstance(report, SDKStreamReport)
assert tuple(chunk.data_bytes() for chunk in report.chunks if isinstance(chunk, SDKBytesChunk)) == (
b"first",
b"second",
)
@pytest.mark.asyncio
@pytest.mark.parametrize("mode", ("sync", "async"))
@pytest.mark.parametrize(
"candidate_error",
(
ValueError("invalid input"),
_PublicStreamError("changed message"),
_PublicStreamError(status_code=429),
_PublicStreamError(code="changed_code"),
_PublicStreamError(error_type="changed_type"),
_PublicStreamError(param="changed_param"),
_PublicStreamError(model="changed_model"),
_PublicStreamError(llm_provider="changed_provider"),
),
ids=("exception", "message", "status", "code", "type", "param", "model", "provider"),
)
async def test_stream_parity_rejects_public_error_changes(
mode: Literal["sync", "async"], candidate_error: Exception
) -> None:
chunks: Final = (_Chunk(value="partial"),)
baseline: Final = await _consume(mode, chunks, _PublicStreamError())
candidate: Final = await _consume(mode, chunks, candidate_error)
with pytest.raises(AssertionError):
assert_stream_parity(baseline, candidate)
@pytest.mark.asyncio
@pytest.mark.parametrize("mode", ("sync", "async"))
@pytest.mark.parametrize("candidate", (("one",), ("one", "two", "three"), ("two", "one"), ("one", "changed")))
async def test_stream_parity_checks_event_sequence(mode: Literal["sync", "async"], candidate: tuple[str, ...]) -> None:
baseline: Final = await _consume(mode, (_Chunk(value="one"), _Chunk(value="two")))
changed: Final = await _consume(mode, tuple(_Chunk(value=value) for value in candidate))
with pytest.raises(AssertionError):
assert_stream_parity(baseline, changed)
@pytest.mark.asyncio
@pytest.mark.parametrize("mode", ("sync", "async"))
async def test_stream_parity_preserves_nested_types_and_ignores_private_fields(mode: Literal["sync", "async"]) -> None:
first: Final = _Chunk(value="same")
second: Final = _Chunk(value="same")
first.set_hidden_param("request_id", "first")
second.set_hidden_param("request_id", "second")
baseline: Final = await _consume(mode, (_NestedChunk(value=[first]),))
candidate: Final = await _consume(mode, (_NestedChunk(value=[second]),))
assert_stream_parity(baseline, candidate)
changed: Final = await _consume(mode, (_NestedChunk(value=[{"value": "same"}]),))
with pytest.raises(AssertionError, match=r"\$\.chunks\[0\]\.value\[0\]"):
assert_stream_parity(baseline, changed)
def test_stream_parity_rejects_wrapper_and_chunk_type_changes() -> None:
baseline: Final = consume_sync_stream(lambda: _SyncStream((_Chunk(value="same"),)))
different_wrapper: Final = consume_sync_stream(lambda: iter((_Chunk(value="same"),)))
different_chunk: Final = consume_sync_stream(lambda: _SyncStream(({"value": "same"},)))
with pytest.raises(AssertionError):
assert_stream_parity(baseline, different_wrapper)
with pytest.raises(AssertionError):
assert_stream_parity(baseline, different_chunk)
@pytest.mark.asyncio
@pytest.mark.parametrize("mode", ("sync", "async"))
@pytest.mark.parametrize("error", (None, _PublicStreamError()))
async def test_capture_keeps_serialization_failures_out_of_sdk_errors(
mode: Literal["sync", "async"], error: Exception | None
) -> None:
with pytest.raises(ValidationError):
await _capture(mode, (_Chunk(value="valid"), object()), error)
@pytest.mark.asyncio
@pytest.mark.parametrize("mode", ("sync", "async"))
async def test_empty_stream_completes(mode: Literal["sync", "async"]) -> None:
outcome: Final = await _consume(mode, ())
assert outcome.chunks == ()
assert outcome.terminal == StreamCompleted()
assert await _capture(mode, ()) == SDKStreamReport(chunks=(), terminal=SDKStreamCompleted())
@pytest.mark.asyncio
async def test_async_creation_error_matches_sync_capture() -> None:
async def create() -> _AsyncStream:
_creation_error()
sync: Final = consume_sync_stream(_creation_error)
asynchronous: Final = await consume_async_stream(create)
assert_stream_parity(sync, asynchronous)
assert isinstance(sync.terminal, StreamFailed)
assert sync.terminal.phase == "creation"
assert isinstance(capture_sync_stream(_creation_error), SDKError)
assert capture_sync_stream(_creation_error) == await capture_async_stream(create) == sync.terminal.error
@pytest.mark.asyncio
@pytest.mark.parametrize("mode", ("sync", "async"))
async def test_capture_preserves_partial_output_and_complete_error(mode: Literal["sync", "async"]) -> None:
error: Final = _PublicStreamError()
report: Final = await _capture(mode, (_Chunk(value="partial"),), error)
assert report == SDKStreamReport(
chunks=(SDKJsonChunk(value={"value": "partial"}),),
terminal=SDKStreamFailed(error=sdk_error_report(error)),
)

View file

@ -44,10 +44,12 @@ class HarnessCase:
coverage: Coverage
selectors: tuple[str, ...]
note: str = ""
surface: str = "sdk"
unit_suite: str | None = None
@property
def key(self) -> str:
return f"{self.strategy_id}:{self.sdk_function}"
return f"{self.strategy_id}:{self.sdk_function}" if self.surface == "sdk" else f"{self.strategy_id}:gateway:{self.sdk_function}"
@dataclass(frozen=True)
@ -96,7 +98,7 @@ class CaseResult:
def set_initial_status(self) -> None:
if self.case.coverage is Coverage.NOT_APPLICABLE:
self.status = RunStatus.NOT_APPLICABLE
elif not self.case.selectors:
elif not self.case.selectors and not self.case.unit_suite:
self.status = RunStatus.PLANNED
else:
self.status = RunStatus.QUEUED
@ -168,12 +170,13 @@ def section_confidence(
) -> tuple[SectionConfidence, ...]:
strategy_list = tuple(strategies)
scores: list[SectionConfidence] = []
for sdk_function in SDK_FUNCTIONS:
sections = tuple(dict.fromkeys((case.surface, case.sdk_function) for strategy in strategy_list for case in strategy.cases))
for surface, sdk_function in sections:
cases = tuple(
case
for strategy in strategy_list
for case in strategy.cases
if case.sdk_function == sdk_function
if case.sdk_function == sdk_function and case.surface == surface
and case.coverage is not Coverage.NOT_APPLICABLE
)
verified = 0
@ -195,7 +198,7 @@ def section_confidence(
level = ConfidenceLevel.LOW
scores.append(
SectionConfidence(
sdk_function=sdk_function,
sdk_function=sdk_function if surface == "sdk" else f"gateway/{sdk_function}",
verified_strategies=verified,
required_strategies=required,
level=level,

View file

@ -0,0 +1,65 @@
from __future__ import annotations
from collections.abc import Callable, Sequence
from pathlib import Path
from time import monotonic
from typing import Final, Protocol
from .models import HarnessCase, HarnessRun
from .pytest_runner import UpdateCallback
class StrategyRunner(Protocol):
def __call__(
self,
cases: Sequence[HarnessCase],
repo_root: Path,
on_update: UpdateCallback,
pytest_args: Sequence[str] = (),
) -> tuple[int, HarnessRun]: ...
def combine_reports(reports: Sequence[HarnessRun]) -> HarnessRun:
return HarnessRun(
results={key: result for report in reports for key, result in report.results.items()},
current_nodeid=next((report.current_nodeid for report in reversed(reports) if report.current_nodeid), None),
failures=[failure for report in reports for failure in report.failures],
started_at=min((report.started_at for report in reports), default=monotonic()),
finished_at=(
max((report.finished_at for report in reports if report.finished_at is not None), default=None)
if all(report.finished_at is not None for report in reports)
else None
),
)
def run_strategies(
cases: Sequence[HarnessCase],
repo_root: Path,
on_update: UpdateCallback,
pytest_args: Sequence[str],
resolve_runner: Callable[[str], StrategyRunner],
) -> tuple[int, HarnessRun]:
strategy_ids: Final = tuple(dict.fromkeys(case.strategy_id for case in cases))
def execute(
remaining: tuple[str, ...], reports: tuple[HarnessRun, ...], codes: tuple[int, ...]
) -> tuple[int, HarnessRun]:
if not remaining:
combined: Final = combine_reports(reports)
on_update(combined)
return next((code for code in codes if code), 0), combined
strategy_id, *tail = remaining
selected: Final = tuple(case for case in cases if case.strategy_id == strategy_id)
pending: Final = HarnessRun.from_cases(case for case in cases if case.strategy_id in tail)
code, report = resolve_runner(strategy_id)(
selected,
repo_root,
lambda current: on_update(combine_reports((*reports, current, pending))),
pytest_args,
)
if code in {2, 3, 4}:
return code, combine_reports((*reports, report, pending))
return execute(tuple(tail), (*reports, report), (*codes, code))
return execute(strategy_ids, (), ())

View file

@ -4,6 +4,7 @@ import os
from collections.abc import Callable, Sequence
from pathlib import Path
from time import monotonic
from typing import Final
import pytest
@ -148,13 +149,22 @@ def run_pytest(
return exit_code, run
plugin = HarnessPytestPlugin(run=run, on_update=on_update)
args = [*selectors, "-p", "no:terminal", *pytest_args]
args: Final = (*selectors, "-q", "--tb=no", "--no-summary", "-o", "consider_namespace_packages=true", *pytest_args)
previous_directory = Path.cwd()
try:
os.chdir(repo_root)
exit_code = int(pytest.main(args, plugins=[plugin]))
exit_code = int(pytest.main(list(args), plugins=[plugin]))
finally:
os.chdir(previous_directory)
for result in run.results.values():
missing = tuple(
selector for selector in result.case.selectors
if not any(selector_matches_node(selector, node) for node in result.collected)
)
if missing:
result.status = RunStatus.MISSING
run.failures.extend((selector, "Configured selector collected no tests") for selector in missing)
on_update(run)
if exit_code == 0 and any(
result.status is RunStatus.MISSING for result in run.results.values()
):

View file

@ -0,0 +1,47 @@
from __future__ import annotations
from pathlib import Path
from typing import Final
from .models import Coverage, HarnessCase, RunStatus
from .orchestration import run_strategies
from .pytest_runner import run_pytest
def test_combines_independent_strategy_reports_and_keeps_failures(tmp_path: Path) -> None:
(tmp_path / "test_first.py").write_text("def test_first():\n assert 1 == 2\n")
(tmp_path / "test_second.py").write_text("def test_second():\n assert True\n")
cases: Final = tuple(
HarnessCase(
strategy_id=name,
strategy_label=name,
sdk_function="ocr",
coverage=Coverage.COMPLETE,
selectors=(f"test_{name}.py",),
)
for name in ("first", "second")
)
code, report = run_strategies(cases, tmp_path, lambda _: None, (), lambda _: run_pytest)
assert code == 1
assert report.results["first:ocr"].status is RunStatus.FAILED
assert report.results["second:ocr"].status is RunStatus.PASSED
assert report.completed_tests == 2
assert len(report.failures) == 1
assert "assert 1 == 2" in report.failures[0][1]
assert "terminalreporter" not in report.failures[0][1]
def test_missing_selector_cannot_hide_behind_a_passing_surface(tmp_path: Path) -> None:
(tmp_path / "test_present.py").write_text("def test_present():\n assert True\n")
case: Final = HarnessCase(
strategy_id="e2e_parity",
strategy_label="End-to-end parity",
sdk_function="ocr",
surface="gateway",
coverage=Coverage.PARTIAL,
selectors=("test_present.py", "test_missing.py"),
)
code, report = run_pytest((case,), tmp_path, lambda _: None)
assert code == 1
assert report.results["e2e_parity:gateway:ocr"].status is RunStatus.MISSING
assert ("test_missing.py", "Configured selector collected no tests") in report.failures

View file

@ -12,7 +12,6 @@ from .models import (
Coverage,
HarnessRun,
RunStatus,
SDK_FUNCTIONS,
Strategy,
section_confidence,
)
@ -52,7 +51,9 @@ def _format_duration(seconds: float) -> str:
def _rerun_command(nodeid: str) -> str:
return f"poetry run pytest {shlex.quote(nodeid)} -q"
if nodeid.startswith("unit-suite:"):
return "uv run python -m tests.rust-python-harness.strategies.unit_tests.runner --plain"
return f"poetry run pytest {shlex.quote(nodeid)} -q -o consider_namespace_packages=true"
def _summary(run: HarnessRun) -> tuple[int, int, int, int]:
@ -67,8 +68,9 @@ def _summary(run: HarnessRun) -> tuple[int, int, int, int]:
)
def _cell_text(run: HarnessRun, strategy_id: str, sdk_function: str) -> tuple[str, str]:
result = run.results.get(f"{strategy_id}:{sdk_function}")
def _cell_text(run: HarnessRun, strategy_id: str, sdk_function: str, surface: str = "sdk") -> tuple[str, str]:
key = f"{strategy_id}:{sdk_function}" if surface == "sdk" else f"{strategy_id}:gateway:{sdk_function}"
result = run.results.get(key)
if result is None:
return "", ""
counts = ""
@ -101,6 +103,7 @@ class RichDashboard(AbstractContextManager["RichDashboard"]):
from rich.table import Table
from rich.text import Text
columns = tuple(dict.fromkeys((case.surface, case.sdk_function) for strategy in self.strategies for case in strategy.cases))
narrow = self.console.width < 96
if narrow:
table = Table(box=box.SIMPLE_HEAVY, expand=True, show_header=False)
@ -108,23 +111,23 @@ class RichDashboard(AbstractContextManager["RichDashboard"]):
table.add_column("Results", ratio=5)
for strategy in self.strategies:
values = []
for sdk_function in SDK_FUNCTIONS:
value, style = _cell_text(run, strategy.id, sdk_function)
for surface, sdk_function in columns:
value, style = _cell_text(run, strategy.id, sdk_function, surface)
if value:
values.append(
Text.assemble((f"{sdk_function} ", "dim"), (value, style))
Text.assemble((f"{surface}/{sdk_function} ", "dim"), (value, style))
)
table.add_row(strategy.label, Text(" ").join(values))
return table
table = Table(box=box.ROUNDED, expand=True, title="Strategy × SDK function")
table = Table(box=box.ROUNDED, expand=True, title="Strategy × API")
table.add_column("Strategy", ratio=3)
for label in SDK_FUNCTIONS:
table.add_column(label, justify="center", ratio=1)
for surface, label in columns:
table.add_column(label if surface == "sdk" else f"gateway/{label}", justify="center", ratio=1)
for strategy in self.strategies:
cells = []
for sdk_function in SDK_FUNCTIONS:
value, style = _cell_text(run, strategy.id, sdk_function)
for surface, sdk_function in columns:
value, style = _cell_text(run, strategy.id, sdk_function, surface)
cells.append(Text(value, style=style))
table.add_row(strategy.label, *cells)
return table
@ -192,7 +195,7 @@ class RichDashboard(AbstractContextManager["RichDashboard"]):
from rich.table import Table
confidence_table = Table(
title="Port confidence by SDK section", box=box.ROUNDED, expand=True
title="Port confidence by API", box=box.ROUNDED, expand=True
)
confidence_table.add_column("SDK section")
confidence_table.add_column("Score", justify="right")
@ -256,9 +259,10 @@ class PlainDashboard(AbstractContextManager["PlainDashboard"]):
f"{skipped} skipped in {_format_duration(run.duration)}",
flush=True,
)
for nodeid, _ in run.failures[:5]:
for nodeid, detail in run.failures[:5]:
print(f"{nodeid}: {detail}", flush=True)
print(f"Rerun: {_rerun_command(nodeid)}", flush=True)
print("Port confidence by SDK section", flush=True)
print("Port confidence by API", flush=True)
for score in section_confidence(run, self.confidence_strategies):
print(
f" {score.sdk_function:12} "

View file

@ -0,0 +1,57 @@
from __future__ import annotations
from collections import Counter
from collections.abc import Mapping, Sequence
from dataclasses import dataclass
from typing import Final
@dataclass(frozen=True, slots=True)
class Operation:
name: str
started: int
finished: int
def compare_traces(
python: Sequence[Operation],
rust: Sequence[Operation],
mapping: Mapping[str, str],
required_order: Sequence[tuple[str, str]] = (),
) -> tuple[str, ...]:
python_names: Final = {operation.name for operation in python}
rust_names: Final = {operation.name for operation in rust}
problems: Final = (
*(f"unmapped Python operation: {name}" for name in sorted(python_names - mapping.keys())),
*(f"unmapped Rust operation: {name}" for name in sorted(rust_names - set(mapping.values()))),
*(f"ambiguous Rust operation: {name}" for name, count in Counter(mapping.values()).items() if count > 1),
*(
f"invalid interval: {operation.name}"
for operation in (*python, *rust)
if operation.started > operation.finished
),
)
if problems:
return problems
python_counts: Final = Counter(operation.name for operation in python)
rust_counts: Final = Counter(operation.name for operation in rust)
counts: Final = tuple(
f"call count differs for {name}: Python={python_counts[name]}, Rust={rust_counts[target]}"
for name, target in mapping.items()
if python_counts[name] != rust_counts[target]
)
ordering: Final = tuple(
f"{label}: required order {before} before {after} was not observed"
for before, after in required_order
for label, operations, first, second in (
("Python", python, before, after),
("Rust", rust, mapping.get(before), mapping.get(after)),
)
if not first
or not second
or not any(operation.name == first for operation in operations)
or not any(operation.name == second for operation in operations)
or max(operation.finished for operation in operations if operation.name == first)
> min(operation.started for operation in operations if operation.name == second)
)
return (*counts, *ordering)

View file

@ -0,0 +1,33 @@
from __future__ import annotations
import pytest
from .compare import Operation, compare_traces
@pytest.mark.parametrize(
("rust", "message"),
(
((Operation("decode", 0, 1), Operation("send", 2, 3)), None),
((Operation("decode", 0, 1), Operation("send", 2, 3), Operation("send", 4, 5)), "call count differs"),
((Operation("send", 0, 1), Operation("decode", 2, 3)), "required order"),
((Operation("decode", 0, 4), Operation("send", 2, 3)), "required order"),
((Operation("decode", 0, 1), Operation("unknown", 2, 3)), "unmapped Rust"),
),
)
def test_compare_mapped_calls_and_required_completion_order(rust: tuple[Operation, ...], message: str | None) -> None:
problems = compare_traces(
(Operation("parse", 0, 1), Operation("request", 2, 3)),
rust,
{"parse": "decode", "request": "send"},
(("parse", "request"),),
)
if message is None:
assert problems == ()
else:
assert any(message in problem for problem in problems)
def test_missing_required_operations_and_ambiguous_mappings_fail() -> None:
assert compare_traces((), (), {"parse": "decode"}, (("parse", "request"),))
assert compare_traces((), (), {"parse": "decode", "request": "decode"}) == ("ambiguous Rust operation: decode",)

View file

@ -0,0 +1,5 @@
# E2E Parity
Run independently with `uv run python -m tests.rust-python-harness.strategies.e2e_parity.runner --plain`. Configure SDK and gateway selectors in `strategy.json`; keep API-specific execution and fixtures in their owning surface folder
See [the harness guide](../../README.md) for coverage status and shared comparison tools

View file

@ -0,0 +1,26 @@
from __future__ import annotations
from collections.abc import Sequence
from pathlib import Path
from ...shared.reporting.models import HarnessCase, HarnessRun
from ...shared.reporting.pytest_runner import UpdateCallback, run_pytest
def run(
cases: Sequence[HarnessCase],
repo_root: Path,
on_update: UpdateCallback,
pytest_args: Sequence[str] = (),
) -> tuple[int, HarnessRun]:
return run_pytest(cases, repo_root, on_update, pytest_args)
def main(argv: Sequence[str] | None = None) -> int:
from ...cli import main as harness_main
return harness_main(argv, strategy_id="e2e_parity")
if __name__ == "__main__":
raise SystemExit(main())

View file

@ -0,0 +1,43 @@
from __future__ import annotations
from typing import Final
import pytest
from .....shared.parity.fixtures.pytest_support import parametrize_recorded_fixtures
from .....shared.parity.fixtures.store import fixture_id
from .fixtures.config import DEFAULT_FIXTURE_DIRECTORY, FIXTURE_DIR_ENV
from .fixtures.models import OcrParityCase
def ocr_fixture_id(fixture: OcrParityCase) -> str:
case_input: Final = fixture.litellm_input
provider: Final = case_input.custom_llm_provider
prefix: Final = f"{provider}/{case_input.model}" if provider else case_input.model
return fixture_id(case_input, prefix)
def ocr_fixture_marks(fixture: OcrParityCase) -> tuple[pytest.MarkDecorator, ...]:
if fixture.litellm_input.contract not in {"reducto_v3", "reducto_legacy"}:
return ()
return (
pytest.mark.xfail(
reason="Reducto does not have a Rust OCR contract",
strict=False,
),
)
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
parametrize_recorded_fixtures(
metafunc,
fixture_name="ocr_fixture",
case_type=OcrParityCase,
env_var=FIXTURE_DIR_ENV,
default_directory=DEFAULT_FIXTURE_DIRECTORY,
regeneration_command=(
f"uv run python -m tests.rust-python-harness.strategies.e2e_parity.sdk.ocr.fixtures.record --fixture-dir {DEFAULT_FIXTURE_DIRECTORY}"
),
id_builder=ocr_fixture_id,
marks_builder=ocr_fixture_marks,
)

View file

@ -0,0 +1,49 @@
# OCR parity fixtures
The recording command runs four stages:
1. Generate deterministic SDK inputs for every configured OCR target
2. Build target-scoped, deduplicated recording jobs
3. Record upstream responses through one globally bounded worker pool
4. Persist each fixture and report whether it was recorded, cached, or failed
Run it with:
```shell
uv run python -m tests.rust-python-harness.strategies.e2e_parity.sdk.ocr.fixtures.record --examples 4 --concurrency 4
```
`--concurrency` caps provider calls across all targets. Independent jobs finish after a failure, then the command exits
nonzero if any job failed
New recordings are VCR YAML cassettes. The committed corpus contains 31 migrated cassettes: 18 Mistral, 9 Reducto v3,
and 4 Reducto legacy. Their original response bytes, statuses, headers, and recording timestamps are preserved
To migrate an existing JSON fixture directory locally:
```shell
uv run python -m tests.rust-python-harness.strategies.e2e_parity.sdk.ocr.fixtures.migrate --fixture-dir tests/rust-python-harness/strategies/e2e_parity/sdk/ocr/fixtures/data
```
The migration replays each old response through the Python SDK to reconstruct missing requests, writes and validates
the YAML cassette, then removes its JSON predecessor. It calls only local recording/replay servers and needs no provider
credentials. Reconstructed requests are labeled `python_replay`; they are not historical wire captures. Filenames use
the current normalized SDK input hash, including the fixture contract
OCR strategies generate public `litellm.ocr()` and `litellm.aocr()` inputs. Every case contains the normalized model,
document, optional provider override, and LiteLLM keyword arguments. The fixture-only `contract` literal selects the
input schema and is removed before calling the SDK. Strategies never build provider wire payloads
Each contract has a required corpus containing a baseline and cases for its supported top-level OCR parameters. The
contracts are Mistral, Azure-hosted Mistral, Vertex-hosted Mistral, Azure Document Intelligence, Vertex DeepSeek,
Reducto v3, and Reducto legacy. Credentials and endpoints only control target discovery, so a machine records the
contracts it has configured and skips the rest
Reducto fixtures record upload and parse responses. Their parity cases remain non-strict expected failures until the
Rust OCR bridge supports Reducto. Azure and Vertex generation paths are unit-tested without credentials in CI, so the
committed corpus does not need live recordings for every target
Every recording target owns a small fixed provider-rejected corpus, independent of replay implementation support.
Those inputs are recorded separately from generated valid inputs. Local validation failures use no recorded response;
the parity suite checks those unsupported providers and models, malformed documents, invalid request formats, invalid
Azure Document Intelligence parameters, and invalid headers in sync and async SDK calls

View file

@ -0,0 +1,207 @@
from __future__ import annotations
from collections.abc import Mapping
from typing import Final, Literal, cast
from hypothesis import strategies as st
from hypothesis.strategies import SearchStrategy
from pydantic import StrictInt, StrictStr, field_validator
from ......shared.parity.fixtures.recording import UpstreamEndpoint
from .base import OcrDocument, OcrSdkInputBase
from .common import (
OcrFixtureClient,
OcrRecordingTarget,
image_document,
invoke_with_api_key,
pdf_document,
)
from .mistral import (
MistralCompatibleOcrSdkInput,
mistral_input_values_strategy,
)
AzureMistralModel = Literal["azure_ai/mistral-document-ai-2512",]
AzureMistralFixtureModel = AzureMistralModel | Literal["azure_ai/invalid-ocr-model-for-parity"]
AzureDocumentIntelligenceModel = Literal[
"azure_ai/doc-intelligence/prebuilt-read",
"azure_ai/doc-intelligence/prebuilt-layout",
"azure_ai/doc-intelligence/prebuilt-document",
]
AzureDocumentIntelligenceFixtureModel = (
AzureDocumentIntelligenceModel | Literal["azure_ai/doc-intelligence/invalid-ocr-model-for-parity"]
)
AZURE_MISTRAL_MODELS: Final[tuple[AzureMistralModel, ...]] = ("azure_ai/mistral-document-ai-2512",)
AZURE_DOCUMENT_INTELLIGENCE_MODELS: Final[tuple[AzureDocumentIntelligenceModel, ...]] = (
"azure_ai/doc-intelligence/prebuilt-read",
"azure_ai/doc-intelligence/prebuilt-layout",
"azure_ai/doc-intelligence/prebuilt-document",
)
# API v4 replaces prebuilt-document with prebuilt-layout plus keyValuePairs. Keep
# the broader fixture model above so existing recordings remain loadable.
AZURE_DOCUMENT_INTELLIGENCE_RECORDING_MODELS: Final[tuple[AzureDocumentIntelligenceModel, ...]] = (
"azure_ai/doc-intelligence/prebuilt-read",
"azure_ai/doc-intelligence/prebuilt-layout",
)
class AzureMistralOcrSdkInput(MistralCompatibleOcrSdkInput):
contract: Literal["azure_mistral"] = "azure_mistral"
model: AzureMistralFixtureModel
custom_llm_provider: Literal["azure_ai"] | None = None
@field_validator("model")
@classmethod
def validate_model_namespace(cls, model: str) -> str:
if not model.startswith("azure_ai/"):
raise ValueError("Azure Mistral models must use the azure_ai/ LiteLLM namespace")
return model
class AzureDocumentIntelligenceOcrSdkInput(OcrSdkInputBase):
contract: Literal["azure_document_intelligence"] = "azure_document_intelligence"
model: AzureDocumentIntelligenceFixtureModel
document: OcrDocument
custom_llm_provider: Literal["azure_ai"] | None = None
pages: str | list[StrictInt] | list[StrictStr] | None = None
features: str | list[str] | None = None
req_format: Literal["litellm"] = "litellm"
AZURE_MISTRAL_PROVIDER_REJECTED_INPUTS: Final[tuple[AzureMistralOcrSdkInput, ...]] = (
AzureMistralOcrSdkInput(
model="azure_ai/invalid-ocr-model-for-parity",
document=pdf_document(),
),
)
AZURE_DOCUMENT_INTELLIGENCE_PROVIDER_REJECTED_INPUTS: Final[tuple[AzureDocumentIntelligenceOcrSdkInput, ...]] = (
AzureDocumentIntelligenceOcrSdkInput(
model="azure_ai/doc-intelligence/invalid-ocr-model-for-parity",
document=pdf_document(),
),
)
def _azure_mistral_input(values: dict[str, object], model: AzureMistralModel) -> AzureMistralOcrSdkInput:
return AzureMistralOcrSdkInput.model_validate({**values, "model": model})
def azure_mistral_input_strategy(inline_image_data_uri: str) -> SearchStrategy[AzureMistralOcrSdkInput]:
# Foundry's active gateway schema rejects 2512-only controls and
# document_annotation_prompt, even though native Mistral accepts them.
return st.builds(
_azure_mistral_input,
values=mistral_input_values_strategy("2505", inline_image_data_uri, include_document_annotation_prompt=False),
model=st.sampled_from(AZURE_MISTRAL_MODELS),
)
_AZURE_DOCUMENT_INTELLIGENCE_CANONICAL_MODEL: Final[AzureDocumentIntelligenceModel] = (
"azure_ai/doc-intelligence/prebuilt-layout"
)
def _document_intelligence_input(
model: AzureDocumentIntelligenceModel,
document: OcrDocument,
optional_params: Mapping[str, object] | None = None,
) -> AzureDocumentIntelligenceOcrSdkInput:
return AzureDocumentIntelligenceOcrSdkInput.model_validate(
{"model": model, "document": document, **(optional_params or {})}
)
def azure_document_intelligence_input_strategy() -> SearchStrategy[AzureDocumentIntelligenceOcrSdkInput]:
document: Final = pdf_document()
pages: Final = st.one_of(
st.sampled_from(((0,), (2, 0, 0, 1))).map(list),
st.just(["1", "2-4"]),
st.just("1-4, 5"),
).map(lambda value: {"pages": value})
features: Final = st.one_of(
st.sampled_from(
(
("languages",),
("ocrHighResolution",),
("barcodes",),
("formulas",),
("styleFont",),
("keyValuePairs",),
)
).map(list),
st.just("languages, styleFont"),
).map(lambda value: {"features": value})
combined_query: Final = st.just({"pages": (0, 1), "features": ("languages", "styleFont")})
return st.one_of(
st.sampled_from(AZURE_DOCUMENT_INTELLIGENCE_RECORDING_MODELS).map(
lambda model: _document_intelligence_input(model, document)
),
st.just(
_document_intelligence_input(
_AZURE_DOCUMENT_INTELLIGENCE_CANONICAL_MODEL,
image_document("invoice 123", 24),
)
),
pages.map(
lambda optional_params: _document_intelligence_input(
_AZURE_DOCUMENT_INTELLIGENCE_CANONICAL_MODEL, document, optional_params
)
),
features.map(
lambda optional_params: _document_intelligence_input(
_AZURE_DOCUMENT_INTELLIGENCE_CANONICAL_MODEL, document, optional_params
)
),
combined_query.map(
lambda optional_params: _document_intelligence_input(
_AZURE_DOCUMENT_INTELLIGENCE_CANONICAL_MODEL, document, optional_params
)
),
st.just(
_document_intelligence_input(
_AZURE_DOCUMENT_INTELLIGENCE_CANONICAL_MODEL,
document,
{"req_format": "litellm"},
)
),
)
def azure_mistral_recording_targets(
environ: Mapping[str, str], client: OcrFixtureClient, inline_image_data_uri: str
) -> tuple[OcrRecordingTarget, ...]:
api_key: Final = environ.get("AZURE_AI_API_KEY")
base_url: Final = environ.get("AZURE_AI_API_BASE")
if not api_key or not base_url:
return ()
return (
OcrRecordingTarget(
name="azure-mistral",
upstream=UpstreamEndpoint(base_url=base_url.rstrip("/")),
strategy=cast(
SearchStrategy[OcrSdkInputBase],
azure_mistral_input_strategy(inline_image_data_uri),
),
invocation=invoke_with_api_key(client, api_key),
required_inputs=AZURE_MISTRAL_PROVIDER_REJECTED_INPUTS,
),
)
def azure_document_intelligence_recording_targets(
environ: Mapping[str, str], client: OcrFixtureClient
) -> tuple[OcrRecordingTarget, ...]:
api_key: Final = environ.get("AZURE_DOCUMENT_INTELLIGENCE_API_KEY")
base_url: Final = environ.get("AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT")
if not api_key or not base_url:
return ()
return (
OcrRecordingTarget(
name="azure-document-intelligence",
upstream=UpstreamEndpoint(base_url=base_url.rstrip("/")),
strategy=cast(SearchStrategy[OcrSdkInputBase], azure_document_intelligence_input_strategy()),
invocation=invoke_with_api_key(client, api_key),
required_inputs=AZURE_DOCUMENT_INTELLIGENCE_PROVIDER_REJECTED_INPUTS,
),
)

View file

@ -0,0 +1,48 @@
from __future__ import annotations
from typing import Annotated, Literal
from pydantic import Field
from ......shared.parity.fixture_models import (
FixtureModel,
JsonSchemaDefinition,
JsonSchemaResponseFormat,
SdkInputBase,
)
__all__ = (
"DocumentUrlDocument",
"ImageUrlDocument",
"ImageUrlValue",
"JsonSchemaDefinition",
"JsonSchemaResponseFormat",
"OcrDocument",
"OcrSdkInputBase",
)
class OcrSdkInputBase(SdkInputBase):
fixture_only_fields = ("contract",)
class ImageUrlValue(FixtureModel):
url: str
detail: Literal["low", "auto", "high"] | None = None
class ImageUrlDocument(FixtureModel):
type: Literal["image_url"]
image_url: str | ImageUrlValue
class DocumentUrlDocument(FixtureModel):
type: Literal["document_url"]
document_url: str
document_name: str | None = None
OcrDocument = Annotated[
ImageUrlDocument | DocumentUrlDocument,
Field(discriminator="type"),
]

View file

@ -0,0 +1,101 @@
from __future__ import annotations
from dataclasses import dataclass, field
from functools import cache
from typing import Final, Literal, Protocol
from hypothesis import strategies as st
from hypothesis.strategies import SearchStrategy
from ......shared.parity.fixtures.pipeline import RecordingTarget
from ......shared.parity.fixtures.media import dummy_image_url, structured_pdf_data_uri
from .base import (
DocumentUrlDocument,
ImageUrlDocument,
JsonSchemaDefinition,
JsonSchemaResponseFormat,
OcrSdkInputBase,
)
OcrRecordingTarget = RecordingTarget[OcrSdkInputBase]
class OcrFixtureClient(Protocol):
def execute(self, api_base: str, api_key: str, case_input: OcrSdkInputBase) -> None: ...
class OcrSdkCall(Protocol):
def __call__(self, **kwargs: object) -> object: ...
@dataclass(frozen=True, slots=True)
class ApiKeyOcrInvocation:
client: OcrFixtureClient
api_key: str = field(repr=False)
def execute(self, provider_url: str, case_input: OcrSdkInputBase) -> None:
self.client.execute(provider_url, self.api_key, case_input)
def image_document(text: str, font_size: int) -> ImageUrlDocument:
return ImageUrlDocument(type="image_url", image_url=dummy_image_url(text, font_size))
def image_data_document(data_uri: str) -> ImageUrlDocument:
return ImageUrlDocument(type="image_url", image_url=data_uri)
@cache
def remote_pdf_document() -> DocumentUrlDocument:
return DocumentUrlDocument(
type="document_url",
document_url="https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
)
@cache
def pdf_document() -> DocumentUrlDocument:
return DocumentUrlDocument(type="document_url", document_url=structured_pdf_data_uri())
def document_transport_strategy(inline_image_data_uri: str) -> SearchStrategy[ImageUrlDocument | DocumentUrlDocument]:
transports: Final[tuple[Literal["remote_image", "inline_image", "remote_pdf", "inline_pdf"], ...]] = (
"remote_image",
"inline_image",
"remote_pdf",
"inline_pdf",
)
def as_document(
transport: Literal["remote_image", "inline_image", "remote_pdf", "inline_pdf"],
) -> ImageUrlDocument | DocumentUrlDocument:
if transport == "remote_image":
return image_document("invoice 123", 24)
if transport == "inline_image":
return image_data_document(inline_image_data_uri)
if transport == "remote_pdf":
return remote_pdf_document()
return pdf_document()
return st.sampled_from(transports).map(as_document)
def annotation_format(name: str) -> JsonSchemaResponseFormat:
return JsonSchemaResponseFormat(
type="json_schema",
json_schema=JsonSchemaDefinition(
name=name,
description="Extract the visible document fields",
schema={
"type": "object",
"properties": {"title": {"type": "string"}},
"required": ["title"],
"additionalProperties": False,
},
strict=True,
),
)
def invoke_with_api_key(client: OcrFixtureClient, api_key: str) -> ApiKeyOcrInvocation:
return ApiKeyOcrInvocation(client=client, api_key=api_key)

View file

@ -0,0 +1,13 @@
from __future__ import annotations
import os
from pathlib import Path
from typing import Final
FIXTURE_DIR_ENV: Final = "LITELLM_OCR_FIXTURE_DIR"
DEFAULT_FIXTURE_DIRECTORY: Final = Path(__file__).with_name("data")
def configured_fixture_directory() -> Path:
configured: Final = os.environ.get(FIXTURE_DIR_ENV)
return Path(configured).expanduser() if configured is not None else DEFAULT_FIXTURE_DIRECTORY

View file

@ -0,0 +1,68 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"image_limit":1}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":null,"usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d3637dc2c090-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:15 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-5a87-7148-8ae4-4e14967bebf3
x-envoy-upstream-service-time:
- '226'
x-kong-proxy-latency:
- '19'
x-kong-request-id:
- 01a05e89-5a87-7148-8ae4-4e14967bebf3
x-kong-upstream-latency:
- '227'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '56'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:15.394028+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
image_limit: 1
model: mistral/mistral-ocr-latest
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,69 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"pages":[0]}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":null,"usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d35d1fbbebe5-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:14 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-5685-747f-b76d-dab242ea7512
x-envoy-upstream-service-time:
- '179'
x-kong-proxy-latency:
- '12'
x-kong-request-id:
- 01a05e89-5685-747f-b76d-dab242ea7512
x-kong-upstream-latency:
- '180'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '58'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:14.385374+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
model: mistral/mistral-ocr-latest
pages:
- 0
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,85 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"document_annotation_format":{"type":"json_schema","json_schema":{"name":"document_title","description":"Extract
the visible document fields","schema":{"additionalProperties":false,"properties":{"title":{"type":"string"}},"required":["title"],"type":"object"},"strict":true}},"document_annotation_prompt":"Extract
the visible title"}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":"{\"title\":
\"invoice 123\"}","usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d376581f74f9-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:18 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-664a-740d-a112-0a1183c302b3
x-envoy-upstream-service-time:
- '402'
x-kong-proxy-latency:
- '20'
x-kong-request-id:
- 01a05e89-664a-740d-a112-0a1183c302b3
x-kong-upstream-latency:
- '403'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '52'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:18.915814+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
document_annotation_format:
json_schema:
description: Extract the visible document fields
name: document_title
schema:
additionalProperties: false
properties:
title:
type: string
required:
- title
type: object
strict: true
type: json_schema
document_annotation_prompt: Extract the visible title
model: mistral/mistral-ocr-latest
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,68 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"extract_header":true}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":null,"usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d37c9944d8a7-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:19 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-6a3a-76c7-85b8-d40a7156155e
x-envoy-upstream-service-time:
- '230'
x-kong-proxy-latency:
- '16'
x-kong-request-id:
- 01a05e89-6a3a-76c7-85b8-d40a7156155e
x-kong-upstream-latency:
- '230'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '51'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:19.420285+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
extract_header: true
model: mistral/mistral-ocr-latest
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,67 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"}}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":null,"usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d356fb3698ce-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:13 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-52b4-7e7b-983e-5bc4e5469b39
x-envoy-upstream-service-time:
- '554'
x-kong-proxy-latency:
- '13'
x-kong-request-id:
- 01a05e89-52b4-7e7b-983e-5bc4e5469b39
x-kong-upstream-latency:
- '557'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '59'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:13.880852+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
model: mistral/mistral-ocr-latest
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,82 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"bbox_annotation_format":{"type":"json_schema","json_schema":{"name":"bounding_boxes","description":"Extract
the visible document fields","schema":{"additionalProperties":false,"properties":{"title":{"type":"string"}},"required":["title"],"type":"object"},"strict":true}}}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":null,"usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d369be838fc5-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:16 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-5e6e-70ac-890d-c0110a5e81af
x-envoy-upstream-service-time:
- '210'
x-kong-proxy-latency:
- '17'
x-kong-request-id:
- 01a05e89-5e6e-70ac-890d-c0110a5e81af
x-kong-upstream-latency:
- '212'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '54'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:16.402593+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
bbox_annotation_format:
json_schema:
description: Extract the visible document fields
name: bounding_boxes
schema:
additionalProperties: false
properties:
title:
type: string
required:
- title
type: object
strict: true
type: json_schema
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
model: mistral/mistral-ocr-latest
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,92 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"document_url","document_url":"data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg=="},"pages":[0],"include_image_base64":true,"image_limit":1,"image_min_size":300,"bbox_annotation_format":{"type":"json_schema","json_schema":{"name":"bounding_boxes","description":"Extract
the visible document fields","schema":{"additionalProperties":false,"properties":{"title":{"type":"string"}},"required":["title"],"type":"object"},"strict":true}},"extract_header":true,"extract_footer":false,"table_format":"markdown","confidence_scores_granularity":"page","include_blocks":false,"id":"case-1"}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"Test PDF File","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":93,"height":1023,"width":791},"confidence_scores":{"word_confidence_scores":[],"average_page_confidence_score":0.9376229744322936,"minimum_page_confidence_score":0.22590550796036835},"blocks":null}],"model":"mistral-ocr-latest","document_annotation":null,"usage_info":{"pages_processed":1,"doc_size_bytes":589}}'
headers:
CF-RAY:
- a346d39c1fe5cf12-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:24 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-7deb-72b4-976d-4c244b056782
x-envoy-upstream-service-time:
- '373'
x-kong-proxy-latency:
- '17'
x-kong-request-id:
- 01a05e89-7deb-72b4-976d-4c244b056782
x-kong-upstream-latency:
- '373'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '45'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:24.951956+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
bbox_annotation_format:
json_schema:
description: Extract the visible document fields
name: bounding_boxes
schema:
additionalProperties: false
properties:
title:
type: string
required:
- title
type: object
strict: true
type: json_schema
confidence_scores_granularity: page
contract: mistral
document:
document_url: data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg==
type: document_url
extract_footer: false
extract_header: true
id: case-1
image_limit: 1
image_min_size: 300
include_blocks: false
include_image_base64: true
model: mistral/mistral-ocr-latest
pages:
- 0
table_format: markdown
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,83 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"document_annotation_format":{"type":"json_schema","json_schema":{"name":"document_title","description":"Extract
the visible document fields","schema":{"additionalProperties":false,"properties":{"title":{"type":"string"}},"required":["title"],"type":"object"},"strict":true}}}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":"{\"title\":
\"Invoice_123\"}","usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d36cd82f15ba-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:17 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-6060-71cb-9e35-66ab873b99f3
x-envoy-upstream-service-time:
- '888'
x-kong-proxy-latency:
- '12'
x-kong-request-id:
- 01a05e89-6060-71cb-9e35-66ab873b99f3
x-kong-upstream-latency:
- '889'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '53'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:17.908846+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
document_annotation_format:
json_schema:
description: Extract the visible document fields
name: document_title
schema:
additionalProperties: false
properties:
title:
type: string
required:
- title
type: object
strict: true
type: json_schema
model: mistral/mistral-ocr-latest
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,68 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"include_image_base64":true}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":null,"usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d360593c138a-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:14 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-588e-7e32-a54b-f816bc6c1dc4
x-envoy-upstream-service-time:
- '242'
x-kong-proxy-latency:
- '16'
x-kong-request-id:
- 01a05e89-588e-7e32-a54b-f816bc6c1dc4
x-kong-upstream-latency:
- '242'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '57'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:14.889667+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
include_image_base64: true
model: mistral/mistral-ocr-latest
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,68 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"image_min_size":300}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":null,"usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d36688d203c2-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:15 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-5c60-769b-abf3-44dcefdf5282
x-envoy-upstream-service-time:
- '272'
x-kong-proxy-latency:
- '17'
x-kong-request-id:
- 01a05e89-5c60-769b-abf3-44dcefdf5282
x-kong-upstream-latency:
- '273'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '55'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:15.898087+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
image_min_size: 300
model: mistral/mistral-ocr-latest
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,68 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"id":"case-1"}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":null,"usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d398da783ad4-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:23 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-7bdc-74c5-b8eb-15fbd25b6cfd
x-envoy-upstream-service-time:
- '182'
x-kong-proxy-latency:
- '22'
x-kong-request-id:
- 01a05e89-7bdc-74c5-b8eb-15fbd25b6cfd
x-kong-upstream-latency:
- '183'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '46'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:23.946966+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
id: case-1
model: mistral/mistral-ocr-latest
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,67 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"include_blocks":false}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":null}],"model":"mistral-ocr-latest","document_annotation":null,"usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d392a8432af7-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:22 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-7802-768c-bf57-9021a209ab48
x-envoy-upstream-service-time:
- '213'
x-kong-proxy-latency:
- '17'
x-kong-request-id:
- 01a05e89-7802-768c-bf57-9021a209ab48
x-kong-upstream-latency:
- '214'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '47'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:23.442341+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
include_blocks: false
model: mistral/mistral-ocr-latest
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,68 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"confidence_scores_granularity":"page"}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":{"word_confidence_scores":[],"average_page_confidence_score":0.90845564554897,"minimum_page_confidence_score":0.16168208839823475},"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":null,"usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d38c59681749-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:22 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-7411-7d2c-9e43-01320e4cad1c
x-envoy-upstream-service-time:
- '329'
x-kong-proxy-latency:
- '14'
x-kong-request-id:
- 01a05e89-7411-7d2c-9e43-01320e4cad1c
x-kong-upstream-latency:
- '330'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '48'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:22.437385+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
confidence_scores_granularity: page
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
model: mistral/mistral-ocr-latest
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,68 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"extract_footer":true}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":null,"usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d37fde0f1703-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:20 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-6c42-7ea1-b08b-07cae50734e0
x-envoy-upstream-service-time:
- '523'
x-kong-proxy-latency:
- '13'
x-kong-request-id:
- 01a05e89-6c42-7ea1-b08b-07cae50734e0
x-kong-upstream-latency:
- '525'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '50'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:20.425444+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
extract_footer: true
model: mistral/mistral-ocr-latest
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,83 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"document_url","document_url":"data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg=="},"document_annotation_format":{"type":"json_schema","json_schema":{"name":"document_title","description":"Extract
the visible document fields","schema":{"additionalProperties":false,"properties":{"title":{"type":"string"}},"required":["title"],"type":"object"},"strict":true}}}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"Test PDF File","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":93,"height":1023,"width":791},"confidence_scores":null,"blocks":[{"top_left_x":126,"top_left_y":104,"bottom_right_x":229,"bottom_right_y":127,"content":"Test
PDF File","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":"{\"title\":
\"Test_PDF_File\"}","usage_info":{"pages_processed":1,"doc_size_bytes":589}}'
headers:
CF-RAY:
- a346d3a25d0cccb8-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:25 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-81d5-79f8-914d-e3863af2d24b
x-envoy-upstream-service-time:
- '448'
x-kong-proxy-latency:
- '15'
x-kong-request-id:
- 01a05e89-81d5-79f8-914d-e3863af2d24b
x-kong-upstream-latency:
- '449'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '44'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:25.959391+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: mistral
document:
document_url: data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg==
type: document_url
document_annotation_format:
json_schema:
description: Extract the visible document fields
name: document_title
schema:
additionalProperties: false
properties:
title:
type: string
required:
- title
type: object
strict: true
type: json_schema
model: mistral/mistral-ocr-latest
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,68 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"table_format":"markdown"}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":null,"usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d385ffbda0f2-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:21 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-7015-7a8d-a18c-37b9ceacbe77
x-envoy-upstream-service-time:
- '337'
x-kong-proxy-latency:
- '21'
x-kong-request-id:
- 01a05e89-7015-7a8d-a18c-37b9ceacbe77
x-kong-upstream-latency:
- '338'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '49'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:21.430472+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
model: mistral/mistral-ocr-latest
table_format: markdown
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,105 @@
interactions:
- request:
body: '{"model":"mistral-ocr-latest","document":{"type":"image_url","image_url":"https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24"},"pages":[0],"include_image_base64":false,"image_min_size":300,"bbox_annotation_format":{"type":"json_schema","json_schema":{"name":"bounding_boxes","description":"Extract
the visible document fields","schema":{"additionalProperties":false,"properties":{"title":{"type":"string"}},"required":["title"],"type":"object"},"strict":true}},"document_annotation_format":{"type":"json_schema","json_schema":{"name":"document_title","description":"Extract
the visible document fields","schema":{"additionalProperties":false,"properties":{"title":{"type":"string"}},"required":["title"],"type":"object"},"strict":true}},"extract_header":true,"table_format":"markdown","include_blocks":true}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/v1/ocr
response:
body:
string: '{"pages":[{"index":0,"markdown":"invoice 123","images":[],"tables":[],"hyperlinks":[],"header":null,"footer":null,"dimensions":{"dpi":200,"height":300,"width":800},"confidence_scores":null,"blocks":[{"top_left_x":335,"top_left_y":138,"bottom_right_x":464,"bottom_right_y":162,"content":"invoice
123","confidence_scores":null,"type":"text"}]}],"model":"mistral-ocr-latest","document_annotation":"{\"title\":
\"Invoice_123\"}","usage_info":{"pages_processed":1,"doc_size_bytes":4124}}'
headers:
CF-RAY:
- a346d3a89a85f953-SJC
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:26 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000; includeSubDomains; preload
X-Content-Type-Options:
- nosniff
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
mistral-correlation-id:
- 01a05e89-85bd-7075-af53-8e341b35a63e
x-envoy-upstream-service-time:
- '432'
x-kong-proxy-latency:
- '13'
x-kong-request-id:
- 01a05e89-85bd-7075-af53-8e341b35a63e
x-kong-upstream-latency:
- '433'
x-ratelimit-limit-ocr-pages-minute:
- '60'
x-ratelimit-ocr-pages-query-cost:
- '1'
x-ratelimit-remaining-ocr-pages-minute:
- '43'
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:26.965078+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
bbox_annotation_format:
json_schema:
description: Extract the visible document fields
name: bounding_boxes
schema:
additionalProperties: false
properties:
title:
type: string
required:
- title
type: object
strict: true
type: json_schema
contract: mistral
document:
image_url: https://dummyjson.com/image/800x300/ffffff/000000?text=invoice%20123&fontSize=24
type: image_url
document_annotation_format:
json_schema:
description: Extract the visible document fields
name: document_title
schema:
additionalProperties: false
properties:
title:
type: string
required:
- title
type: object
strict: true
type: json_schema
extract_header: true
image_min_size: 300
include_blocks: true
include_image_base64: false
model: mistral/mistral-ocr-latest
pages:
- 0
table_format: markdown
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,70 @@
interactions:
- request:
body: "--3d54cb2e388c04dbfc172c1497aaa396\r\nContent-Disposition: form-data; name=\"file\";
filename=\"document\"\r\nContent-Type: application/pdf\r\n\r\n%PDF-1.4\n1 0
obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n2 0 obj\n<< /Type /Pages /Kids
[3 0 R] /Count 1 >>\nendobj\n3 0 obj\n<< /Type /Page /Parent 2 0 R /Resources
4 0 R /MediaBox [0 0 612 792] /Contents 5 0 R >>\nendobj\n4 0 obj\n<< /Font
<< /F1 << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> >> >>\nendobj\n5
0 obj\n<< /Length 44 >>\nstream\nBT\n/F1 12 Tf\n100 700 Td\n(Test PDF File)
Tj\nET\nendstream\nendobj\nxref\n0 6\n0000000000 65535 f \n0000000009 00000
n \n0000000058 00000 n \n0000000115 00000 n \n0000000214 00000 n \n0000000293
00000 n \ntrailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n385\n%%EOF\n\r\n--3d54cb2e388c04dbfc172c1497aaa396--\r\n"
headers:
Accept:
- '*/*'
Content-Type:
- multipart/form-data; boundary=3d54cb2e388c04dbfc172c1497aaa396
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/upload
response:
body:
string: '{"file_id":"reducto://45d3cbbc-4d77-4967-8941-935b0c4a0493.pdf","presigned_url":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:58 GMT
status:
code: 200
message: ''
- request:
body: '{"document_url":"reducto://45d3cbbc-4d77-4967-8941-935b0c4a0493.pdf"}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/parse
response:
body:
string: '{"response_type":"parse","job_id":"262ed683-ecd8-40b9-a568-f7b7014854c9","duration":2.4146597385406494,"pdf_url":"https://prod-storage20241010144745140900000001.s3.amazonaws.com/org/8bd983d1-47dd-440b-93d8-431412d819bf/a91f568b-6e98-4962-9924-097202093779.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2UOK6OVBOUYL7WYA%2F20260901%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20260901T195456Z&X-Amz-Expires=43200&X-Amz-SignedHeaders=host&X-Amz-Signature=aa77b33e20fc1426307688f55147d57e8d3b2286a787c096b2da016d7d7d0c93","studio_link":"https://studio.reducto.ai/job/cddd635e-5d16-4621-bf48-031e7637dc0b","usage":{"num_pages":1,"credits":1.0,"credit_breakdown":{"page":1.0},"page_billing_breakdown":{"1":["page"]},"non_empty_cell_count":null},"result":{"type":"full","chunks":[{"content":"#
Test PDF File","embed":"# Test PDF File","enriched":null,"enrichment_success":false,"blocks":[{"type":"Title","bbox":{"left":0.16352969387356803,"top":0.10490237663507056,"width":0.11855640077405508,"height":0.011359045881442221,"page":1,"original_page":1},"content":"Test
PDF File","image_url":null,"chart_data":null,"confidence":"high","granular_confidence":{"extract_confidence":null,"parse_confidence":0.7126715332269669},"extra":null}]}],"ocr":null,"custom":null},"parse_mode":null,"document_properties":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:59 GMT
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:59.198829+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: reducto_legacy
custom_llm_provider: reducto
document:
document_url: data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg==
type: document_url
model: parse-legacy
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,39 @@
interactions:
- request:
body: '{"document_url":"reducto://invalid-document-for-parity"}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/parse
response:
body:
string: '{"error":{"code":404,"name":"NOT_FOUND","message":"Document ''The file
may have expired or been deleted. Please re-upload and try again.'' not found"},"detail":"Document
''The file may have expired or been deleted. Please re-upload and try again.''
not found"}'
headers:
Content-Type:
- application/json
Date:
- Wed, 02 Sep 2026 01:14:06 GMT
status:
code: 404
message: ''
recorded_at: '2026-09-02T01:14:06.814847+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: reducto_legacy
document:
document_url: reducto://invalid-document-for-parity
type: document_url
model: reducto/parse-legacy
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,70 @@
interactions:
- request:
body: "--90e8e7e6a71b2a4b14695234a736d695\r\nContent-Disposition: form-data; name=\"file\";
filename=\"document\"\r\nContent-Type: application/pdf\r\n\r\n%PDF-1.4\n1 0
obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n2 0 obj\n<< /Type /Pages /Kids
[3 0 R] /Count 1 >>\nendobj\n3 0 obj\n<< /Type /Page /Parent 2 0 R /Resources
4 0 R /MediaBox [0 0 612 792] /Contents 5 0 R >>\nendobj\n4 0 obj\n<< /Font
<< /F1 << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> >> >>\nendobj\n5
0 obj\n<< /Length 44 >>\nstream\nBT\n/F1 12 Tf\n100 700 Td\n(Test PDF File)
Tj\nET\nendstream\nendobj\nxref\n0 6\n0000000000 65535 f \n0000000009 00000
n \n0000000058 00000 n \n0000000115 00000 n \n0000000214 00000 n \n0000000293
00000 n \ntrailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n385\n%%EOF\n\r\n--90e8e7e6a71b2a4b14695234a736d695--\r\n"
headers:
Accept:
- '*/*'
Content-Type:
- multipart/form-data; boundary=90e8e7e6a71b2a4b14695234a736d695
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/upload
response:
body:
string: '{"file_id":"reducto://b9f242fd-fdb4-4b0a-9535-f11f432c7678.pdf","presigned_url":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:57 GMT
status:
code: 200
message: ''
- request:
body: '{"document_url":"reducto://b9f242fd-fdb4-4b0a-9535-f11f432c7678.pdf","options":{"enhance":{}}}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/parse
response:
body:
string: '{"response_type":"parse","job_id":"25b78189-66fe-46d9-8114-14372a9d442d","duration":2.4146597385406494,"pdf_url":"https://prod-storage20241010144745140900000001.s3.amazonaws.com/org/8bd983d1-47dd-440b-93d8-431412d819bf/a91f568b-6e98-4962-9924-097202093779.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2UOK6OVBOUYL7WYA%2F20260901%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20260901T195456Z&X-Amz-Expires=43200&X-Amz-SignedHeaders=host&X-Amz-Signature=aa77b33e20fc1426307688f55147d57e8d3b2286a787c096b2da016d7d7d0c93","studio_link":"https://studio.reducto.ai/job/cddd635e-5d16-4621-bf48-031e7637dc0b","usage":{"num_pages":1,"credits":1.0,"credit_breakdown":{"page":1.0},"page_billing_breakdown":{"1":["page"]},"non_empty_cell_count":null},"result":{"type":"full","chunks":[{"content":"#
Test PDF File","embed":"# Test PDF File","enriched":null,"enrichment_success":false,"blocks":[{"type":"Title","bbox":{"left":0.16352969387356803,"top":0.10490237663507056,"width":0.11855640077405508,"height":0.011359045881442221,"page":1,"original_page":1},"content":"Test
PDF File","image_url":null,"chart_data":null,"confidence":"high","granular_confidence":{"extract_confidence":null,"parse_confidence":0.7126715332269669},"extra":null}]}],"ocr":null,"custom":null},"parse_mode":null,"document_properties":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:57 GMT
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:58.471820+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: reducto_legacy
document:
document_url: data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg==
type: document_url
enhance: {}
model: reducto/parse-legacy
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,69 @@
interactions:
- request:
body: "--87aea09e72c511f78d32f6eabd194f5c\r\nContent-Disposition: form-data; name=\"file\";
filename=\"document\"\r\nContent-Type: application/pdf\r\n\r\n%PDF-1.4\n1 0
obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n2 0 obj\n<< /Type /Pages /Kids
[3 0 R] /Count 1 >>\nendobj\n3 0 obj\n<< /Type /Page /Parent 2 0 R /Resources
4 0 R /MediaBox [0 0 612 792] /Contents 5 0 R >>\nendobj\n4 0 obj\n<< /Font
<< /F1 << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> >> >>\nendobj\n5
0 obj\n<< /Length 44 >>\nstream\nBT\n/F1 12 Tf\n100 700 Td\n(Test PDF File)
Tj\nET\nendstream\nendobj\nxref\n0 6\n0000000000 65535 f \n0000000009 00000
n \n0000000058 00000 n \n0000000115 00000 n \n0000000214 00000 n \n0000000293
00000 n \ntrailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n385\n%%EOF\n\r\n--87aea09e72c511f78d32f6eabd194f5c--\r\n"
headers:
Accept:
- '*/*'
Content-Type:
- multipart/form-data; boundary=87aea09e72c511f78d32f6eabd194f5c
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/upload
response:
body:
string: '{"file_id":"reducto://a91f568b-6e98-4962-9924-097202093779.pdf","presigned_url":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:53 GMT
status:
code: 200
message: ''
- request:
body: '{"document_url":"reducto://a91f568b-6e98-4962-9924-097202093779.pdf"}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/parse
response:
body:
string: '{"response_type":"parse","job_id":"cddd635e-5d16-4621-bf48-031e7637dc0b","duration":2.4146597385406494,"pdf_url":"https://prod-storage20241010144745140900000001.s3.amazonaws.com/org/8bd983d1-47dd-440b-93d8-431412d819bf/a91f568b-6e98-4962-9924-097202093779.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2UOK6OVBOUYL7WYA%2F20260901%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20260901T195456Z&X-Amz-Expires=43200&X-Amz-SignedHeaders=host&X-Amz-Signature=aa77b33e20fc1426307688f55147d57e8d3b2286a787c096b2da016d7d7d0c93","studio_link":"https://studio.reducto.ai/job/cddd635e-5d16-4621-bf48-031e7637dc0b","usage":{"num_pages":1,"credits":1.0,"credit_breakdown":{"page":1.0},"page_billing_breakdown":{"1":["page"]},"non_empty_cell_count":null},"result":{"type":"full","chunks":[{"content":"#
Test PDF File","embed":"# Test PDF File","enriched":null,"enrichment_success":false,"blocks":[{"type":"Title","bbox":{"left":0.16352969387356803,"top":0.10490237663507056,"width":0.11855640077405508,"height":0.011359045881442221,"page":1,"original_page":1},"content":"Test
PDF File","image_url":null,"chart_data":null,"confidence":"high","granular_confidence":{"extract_confidence":null,"parse_confidence":0.7126715332269669},"extra":null}]}],"ocr":null,"custom":null},"parse_mode":null,"document_properties":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:57 GMT
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:57.246119+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: reducto_legacy
document:
document_url: data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg==
type: document_url
model: reducto/parse-legacy
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,72 @@
interactions:
- request:
body: "--3c37fd2676c46ae1ff34a706baa70fad\r\nContent-Disposition: form-data; name=\"file\";
filename=\"document\"\r\nContent-Type: application/pdf\r\n\r\n%PDF-1.4\n1 0
obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n2 0 obj\n<< /Type /Pages /Kids
[3 0 R] /Count 1 >>\nendobj\n3 0 obj\n<< /Type /Page /Parent 2 0 R /Resources
4 0 R /MediaBox [0 0 612 792] /Contents 5 0 R >>\nendobj\n4 0 obj\n<< /Font
<< /F1 << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> >> >>\nendobj\n5
0 obj\n<< /Length 44 >>\nstream\nBT\n/F1 12 Tf\n100 700 Td\n(Test PDF File)
Tj\nET\nendstream\nendobj\nxref\n0 6\n0000000000 65535 f \n0000000009 00000
n \n0000000058 00000 n \n0000000115 00000 n \n0000000214 00000 n \n0000000293
00000 n \ntrailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n385\n%%EOF\n\r\n--3c37fd2676c46ae1ff34a706baa70fad--\r\n"
headers:
Accept:
- '*/*'
Content-Type:
- multipart/form-data; boundary=3c37fd2676c46ae1ff34a706baa70fad
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/upload
response:
body:
string: '{"file_id":"reducto://671d6e00-6df5-493a-bd9e-8bbf3d77d3ab.pdf","presigned_url":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:36 GMT
status:
code: 200
message: ''
- request:
body: '{"input":"reducto://671d6e00-6df5-493a-bd9e-8bbf3d77d3ab.pdf","retrieval":{"chunking":{"chunk_mode":"page"}}}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/parse
response:
body:
string: '{"response_type":"parse","job_id":"8f15b6dd-f2d2-48e2-a4c9-0230a9ace704","duration":3.7510643005371094,"pdf_url":"https://prod-storage20241010144745140900000001.s3.amazonaws.com/org/8bd983d1-47dd-440b-93d8-431412d819bf/671d6e00-6df5-493a-bd9e-8bbf3d77d3ab.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2UOK6OVBOUYL7WYA%2F20260901%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20260901T195440Z&X-Amz-Expires=43200&X-Amz-SignedHeaders=host&X-Amz-Signature=96a4f904e8d3ca58d399ab21ade69ec0ea62ff5dfee320c5eeaa6eaa0c4e0561","studio_link":"https://studio.reducto.ai/job/8f15b6dd-f2d2-48e2-a4c9-0230a9ace704","usage":{"num_pages":1,"credits":1.0,"credit_breakdown":{"page":1.0},"page_billing_breakdown":{"1":["page"]},"non_empty_cell_count":null},"result":{"type":"full","chunks":[{"content":"#
Test PDF File","embed":"# Test PDF File","enriched":null,"enrichment_success":false,"blocks":[{"type":"Title","bbox":{"left":0.16189574527182748,"top":0.09479295553814121,"width":0.11946290650820875,"height":0.02146414301710507,"page":1,"original_page":1},"content":"Test
PDF File","image_url":null,"chart_data":null,"confidence":"high","granular_confidence":{"extract_confidence":null,"parse_confidence":0.7185355693101882},"extra":null}]}],"ocr":null,"custom":null},"parse_mode":null,"document_properties":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:40 GMT
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:41.233002+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: reducto_v3
document:
document_url: data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg==
type: document_url
model: reducto/parse-v3
retrieval:
chunking:
chunk_mode: page
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,83 @@
interactions:
- request:
body: "--43159c32150fa5f506932c4b4a645ef6\r\nContent-Disposition: form-data; name=\"file\";
filename=\"document\"\r\nContent-Type: application/pdf\r\n\r\n%PDF-1.4\n1 0
obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n2 0 obj\n<< /Type /Pages /Kids
[3 0 R] /Count 1 >>\nendobj\n3 0 obj\n<< /Type /Page /Parent 2 0 R /Resources
4 0 R /MediaBox [0 0 612 792] /Contents 5 0 R >>\nendobj\n4 0 obj\n<< /Font
<< /F1 << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> >> >>\nendobj\n5
0 obj\n<< /Length 44 >>\nstream\nBT\n/F1 12 Tf\n100 700 Td\n(Test PDF File)
Tj\nET\nendstream\nendobj\nxref\n0 6\n0000000000 65535 f \n0000000009 00000
n \n0000000058 00000 n \n0000000115 00000 n \n0000000214 00000 n \n0000000293
00000 n \ntrailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n385\n%%EOF\n\r\n--43159c32150fa5f506932c4b4a645ef6--\r\n"
headers:
Accept:
- '*/*'
Content-Type:
- multipart/form-data; boundary=43159c32150fa5f506932c4b4a645ef6
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/upload
response:
body:
string: '{"file_id":"reducto://f8bf17e8-ca0b-4add-b484-9982d2e4ac2a.pdf","presigned_url":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:50 GMT
status:
code: 200
message: ''
- request:
body: '{"input":"reducto://f8bf17e8-ca0b-4add-b484-9982d2e4ac2a.pdf","formatting":{"add_page_markers":true,"table_output_format":"json","merge_tables":true,"include":["change_tracking","highlight","comments"]}}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/parse
response:
body:
string: '{"response_type":"parse","job_id":"e3792387-8384-45aa-b02e-a84521db116a","duration":1.0497362613677979,"pdf_url":"https://prod-storage20241010144745140900000001.s3.amazonaws.com/org/8bd983d1-47dd-440b-93d8-431412d819bf/f8bf17e8-ca0b-4add-b484-9982d2e4ac2a.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2UOK6OVBOUYL7WYA%2F20260901%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20260901T195452Z&X-Amz-Expires=43200&X-Amz-SignedHeaders=host&X-Amz-Signature=7367275a69dfd53f9fcf9f02777f0fe973e7e541fa1871e0347f788b8c5078f4","studio_link":"https://studio.reducto.ai/job/e3792387-8384-45aa-b02e-a84521db116a","usage":{"num_pages":1,"credits":1.0,"credit_breakdown":{"page":1.0},"page_billing_breakdown":{"1":["page"]},"non_empty_cell_count":null},"result":{"type":"full","chunks":[{"content":"[[START
OF PAGE 1]]\n\n# Test PDF File\n\n[[END OF PAGE 1]]","embed":"[[START OF PAGE
1]]\n\n# Test PDF File\n\n[[END OF PAGE 1]]","enriched":null,"enrichment_success":false,"blocks":[{"type":"Page
Number","bbox":{"left":0.0,"top":0.0,"width":0.0,"height":0.0,"page":1,"original_page":1},"content":"[[START
OF PAGE 1]]","image_url":null,"chart_data":null,"confidence":"high","granular_confidence":{"extract_confidence":null,"parse_confidence":null},"extra":null},{"type":"Title","bbox":{"left":0.16189574527182748,"top":0.09479295553814121,"width":0.11946290650820875,"height":0.02146414301710507,"page":1,"original_page":1},"content":"Test
PDF File","image_url":null,"chart_data":null,"confidence":"high","granular_confidence":{"extract_confidence":null,"parse_confidence":0.7185355693101882},"extra":null},{"type":"Page
Number","bbox":{"left":0.0,"top":0.0,"width":0.0,"height":0.0,"page":1,"original_page":1},"content":"[[END
OF PAGE 1]]","image_url":null,"chart_data":null,"confidence":"high","granular_confidence":{"extract_confidence":null,"parse_confidence":null},"extra":null}]}],"ocr":null,"custom":null},"parse_mode":null,"document_properties":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:52 GMT
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:53.454592+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: reducto_v3
custom_llm_provider: null
document:
document_url: data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg==
type: document_url
formatting:
add_page_markers: true
include:
- change_tracking
- highlight
- comments
merge_tables: true
table_output_format: json
model: reducto/parse-v3
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,70 @@
interactions:
- request:
body: "--ba392e7bb7694af286b0acfe46365a0f\r\nContent-Disposition: form-data; name=\"file\";
filename=\"document\"\r\nContent-Type: application/pdf\r\n\r\n%PDF-1.4\n1 0
obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n2 0 obj\n<< /Type /Pages /Kids
[3 0 R] /Count 1 >>\nendobj\n3 0 obj\n<< /Type /Page /Parent 2 0 R /Resources
4 0 R /MediaBox [0 0 612 792] /Contents 5 0 R >>\nendobj\n4 0 obj\n<< /Font
<< /F1 << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> >> >>\nendobj\n5
0 obj\n<< /Length 44 >>\nstream\nBT\n/F1 12 Tf\n100 700 Td\n(Test PDF File)
Tj\nET\nendstream\nendobj\nxref\n0 6\n0000000000 65535 f \n0000000009 00000
n \n0000000058 00000 n \n0000000115 00000 n \n0000000214 00000 n \n0000000293
00000 n \ntrailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n385\n%%EOF\n\r\n--ba392e7bb7694af286b0acfe46365a0f--\r\n"
headers:
Accept:
- '*/*'
Content-Type:
- multipart/form-data; boundary=ba392e7bb7694af286b0acfe46365a0f
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/upload
response:
body:
string: '{"file_id":"reducto://a6d3c3bb-a6f1-4636-8b3a-ee920b29d387.pdf","presigned_url":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:46 GMT
status:
code: 200
message: ''
- request:
body: '{"input":"reducto://a6d3c3bb-a6f1-4636-8b3a-ee920b29d387.pdf"}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/parse
response:
body:
string: '{"response_type":"parse","job_id":"4a78c975-1865-46fe-8f89-bea92a49e215","duration":1.1194427013397217,"pdf_url":"https://prod-storage20241010144745140900000001.s3.amazonaws.com/org/8bd983d1-47dd-440b-93d8-431412d819bf/6ab9bcf4-1893-4b37-bddb-acda8ce45dfb.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2UOK6OVBOUYL7WYA%2F20260901%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20260901T195445Z&X-Amz-Expires=43200&X-Amz-SignedHeaders=host&X-Amz-Signature=1db61d33f602f13e8444e8580b737b31f346e47493cc7eca7c4fcddbde0dfb43","studio_link":"https://studio.reducto.ai/job/d345549f-5d98-4c62-b3e3-24c990144df4","usage":{"num_pages":1,"credits":1.0,"credit_breakdown":{"page":1.0},"page_billing_breakdown":{"1":["page"]},"non_empty_cell_count":null},"result":{"type":"full","chunks":[{"content":"#
Test PDF File","embed":"# Test PDF File","enriched":null,"enrichment_success":false,"blocks":[{"type":"Title","bbox":{"left":0.16189574527182748,"top":0.09479295553814121,"width":0.11946290650820875,"height":0.02146414301710507,"page":1,"original_page":1},"content":"Test
PDF File","image_url":null,"chart_data":null,"confidence":"high","granular_confidence":{"extract_confidence":null,"parse_confidence":0.7185355693101882},"extra":null}]}],"ocr":null,"custom":null},"parse_mode":null,"document_properties":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:47 GMT
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:47.967951+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: reducto_v3
custom_llm_provider: reducto
document:
document_url: data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg==
type: document_url
model: parse-v3
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,70 @@
interactions:
- request:
body: "--0f6127f8c781afd158616115a5ebdece\r\nContent-Disposition: form-data; name=\"file\";
filename=\"document\"\r\nContent-Type: application/pdf\r\n\r\n%PDF-1.4\n1 0
obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n2 0 obj\n<< /Type /Pages /Kids
[3 0 R] /Count 1 >>\nendobj\n3 0 obj\n<< /Type /Page /Parent 2 0 R /Resources
4 0 R /MediaBox [0 0 612 792] /Contents 5 0 R >>\nendobj\n4 0 obj\n<< /Font
<< /F1 << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> >> >>\nendobj\n5
0 obj\n<< /Length 44 >>\nstream\nBT\n/F1 12 Tf\n100 700 Td\n(Test PDF File)
Tj\nET\nendstream\nendobj\nxref\n0 6\n0000000000 65535 f \n0000000009 00000
n \n0000000058 00000 n \n0000000115 00000 n \n0000000214 00000 n \n0000000293
00000 n \ntrailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n385\n%%EOF\n\r\n--0f6127f8c781afd158616115a5ebdece--\r\n"
headers:
Accept:
- '*/*'
Content-Type:
- multipart/form-data; boundary=0f6127f8c781afd158616115a5ebdece
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/upload
response:
body:
string: '{"file_id":"reducto://6ab9bcf4-1893-4b37-bddb-acda8ce45dfb.pdf","presigned_url":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:44 GMT
status:
code: 200
message: ''
- request:
body: '{"input":"reducto://6ab9bcf4-1893-4b37-bddb-acda8ce45dfb.pdf"}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/parse
response:
body:
string: '{"response_type":"parse","job_id":"d345549f-5d98-4c62-b3e3-24c990144df4","duration":1.1194427013397217,"pdf_url":"https://prod-storage20241010144745140900000001.s3.amazonaws.com/org/8bd983d1-47dd-440b-93d8-431412d819bf/6ab9bcf4-1893-4b37-bddb-acda8ce45dfb.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2UOK6OVBOUYL7WYA%2F20260901%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20260901T195445Z&X-Amz-Expires=43200&X-Amz-SignedHeaders=host&X-Amz-Signature=1db61d33f602f13e8444e8580b737b31f346e47493cc7eca7c4fcddbde0dfb43","studio_link":"https://studio.reducto.ai/job/d345549f-5d98-4c62-b3e3-24c990144df4","usage":{"num_pages":1,"credits":1.0,"credit_breakdown":{"page":1.0},"page_billing_breakdown":{"1":["page"]},"non_empty_cell_count":null},"result":{"type":"full","chunks":[{"content":"#
Test PDF File","embed":"# Test PDF File","enriched":null,"enrichment_success":false,"blocks":[{"type":"Title","bbox":{"left":0.16189574527182748,"top":0.09479295553814121,"width":0.11946290650820875,"height":0.02146414301710507,"page":1,"original_page":1},"content":"Test
PDF File","image_url":null,"chart_data":null,"confidence":"high","granular_confidence":{"extract_confidence":null,"parse_confidence":0.7185355693101882},"extra":null}]}],"ocr":null,"custom":null},"parse_mode":null,"document_properties":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:46 GMT
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:46.694836+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: reducto_v3
custom_llm_provider: null
document:
document_url: data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg==
type: document_url
model: reducto/parse-v3
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,100 @@
interactions:
- request:
body: "--22b7cb49f85a1ae5113a6328b0381ffb\r\nContent-Disposition: form-data; name=\"file\";
filename=\"document\"\r\nContent-Type: application/pdf\r\n\r\n%PDF-1.4\n1 0
obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n2 0 obj\n<< /Type /Pages /Kids
[3 0 R] /Count 1 >>\nendobj\n3 0 obj\n<< /Type /Page /Parent 2 0 R /Resources
4 0 R /MediaBox [0 0 612 792] /Contents 5 0 R >>\nendobj\n4 0 obj\n<< /Font
<< /F1 << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> >> >>\nendobj\n5
0 obj\n<< /Length 44 >>\nstream\nBT\n/F1 12 Tf\n100 700 Td\n(Test PDF File)
Tj\nET\nendstream\nendobj\nxref\n0 6\n0000000000 65535 f \n0000000009 00000
n \n0000000058 00000 n \n0000000115 00000 n \n0000000214 00000 n \n0000000293
00000 n \ntrailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n385\n%%EOF\n\r\n--22b7cb49f85a1ae5113a6328b0381ffb--\r\n"
headers:
Accept:
- '*/*'
Content-Type:
- multipart/form-data; boundary=22b7cb49f85a1ae5113a6328b0381ffb
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/upload
response:
body:
string: '{"file_id":"reducto://5df745f4-2877-4cf6-9bde-a2f829c93eea.pdf","presigned_url":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:48 GMT
status:
code: 200
message: ''
- request:
body: '{"input":"reducto://5df745f4-2877-4cf6-9bde-a2f829c93eea.pdf","formatting":{"add_page_markers":false,"table_output_format":"json","merge_tables":true,"include":["signatures","ignore_watermarks"]},"retrieval":{"chunking":{"chunk_mode":"variable","chunk_size":1500,"chunk_overlap":32},"filter_blocks":["Figure","Table","Key
Value"],"embedding_optimized":false},"settings":{"ocr_system":"legacy","extraction_mode":"hybrid","force_url_result":false,"return_ocr_data":false,"return_images":[],"embed_pdf_metadata":false,"embed_pdf_metadata_dpi":100,"persist_results":false,"timeout":900.0,"page_range":[1]}}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/parse
response:
body:
string: '{"response_type":"parse","job_id":"7ca67242-1677-484e-b2ef-b256dcdd1ea4","duration":1.3359308242797852,"pdf_url":"https://prod-storage20241010144745140900000001.s3.amazonaws.com/org/8bd983d1-47dd-440b-93d8-431412d819bf/5df745f4-2877-4cf6-9bde-a2f829c93eea.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2UOK6OVBOUYL7WYA%2F20260901%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20260901T195449Z&X-Amz-Expires=43200&X-Amz-SignedHeaders=host&X-Amz-Signature=077a6551201d2562fd1543fd5c391541cffe606d64307a3f6d103cf18219f80a","studio_link":"https://studio.reducto.ai/job/7ca67242-1677-484e-b2ef-b256dcdd1ea4","usage":{"num_pages":1,"credits":1.0,"credit_breakdown":{"page":1.0},"page_billing_breakdown":{"1":["page"]},"non_empty_cell_count":null},"result":{"type":"full","chunks":[{"content":"#
Test PDF File","embed":"# Test PDF File","enriched":null,"enrichment_success":false,"blocks":[{"type":"Title","bbox":{"left":0.16189574527182748,"top":0.09479295553814121,"width":0.11946290650820875,"height":0.02146414301710507,"page":1,"original_page":1},"content":"Test
PDF File","image_url":null,"chart_data":null,"confidence":"high","granular_confidence":{"extract_confidence":null,"parse_confidence":0.7185355693101882},"extra":null}]}],"ocr":null,"custom":null},"parse_mode":null,"document_properties":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:50 GMT
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:50.708637+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: reducto_v3
custom_llm_provider: null
document:
document_url: data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg==
type: document_url
formatting:
add_page_markers: false
include:
- signatures
- ignore_watermarks
merge_tables: true
table_output_format: json
model: reducto/parse-v3
retrieval:
chunking:
chunk_mode: variable
chunk_overlap: 32
chunk_size: 1500
embedding_optimized: false
filter_blocks:
- Figure
- Table
- Key Value
settings:
embed_pdf_metadata: false
embed_pdf_metadata_dpi: 100
extraction_mode: hybrid
force_url_result: false
ocr_system: legacy
page_range:
- 1
persist_results: false
return_images: []
return_ocr_data: false
timeout: 900.0
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,72 @@
interactions:
- request:
body: "--7108360c769817ee2464c4729615e289\r\nContent-Disposition: form-data; name=\"file\";
filename=\"document\"\r\nContent-Type: application/pdf\r\n\r\n%PDF-1.4\n1 0
obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n2 0 obj\n<< /Type /Pages /Kids
[3 0 R] /Count 1 >>\nendobj\n3 0 obj\n<< /Type /Page /Parent 2 0 R /Resources
4 0 R /MediaBox [0 0 612 792] /Contents 5 0 R >>\nendobj\n4 0 obj\n<< /Font
<< /F1 << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> >> >>\nendobj\n5
0 obj\n<< /Length 44 >>\nstream\nBT\n/F1 12 Tf\n100 700 Td\n(Test PDF File)
Tj\nET\nendstream\nendobj\nxref\n0 6\n0000000000 65535 f \n0000000009 00000
n \n0000000058 00000 n \n0000000115 00000 n \n0000000214 00000 n \n0000000293
00000 n \ntrailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n385\n%%EOF\n\r\n--7108360c769817ee2464c4729615e289--\r\n"
headers:
Accept:
- '*/*'
Content-Type:
- multipart/form-data; boundary=7108360c769817ee2464c4729615e289
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/upload
response:
body:
string: '{"file_id":"reducto://fc6ebcb1-95d4-46ec-90d0-efca33ef197f.pdf","presigned_url":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:41 GMT
status:
code: 200
message: ''
- request:
body: '{"input":"reducto://fc6ebcb1-95d4-46ec-90d0-efca33ef197f.pdf","settings":{"return_ocr_data":true}}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/parse
response:
body:
string: '{"response_type":"parse","job_id":"3f6ef64d-c949-4b8d-9898-afb3b01669e6","duration":1.4480743408203125,"pdf_url":"https://prod-storage20241010144745140900000001.s3.amazonaws.com/org/8bd983d1-47dd-440b-93d8-431412d819bf/fc6ebcb1-95d4-46ec-90d0-efca33ef197f.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2UOK6OVBOUYL7WYA%2F20260901%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20260901T195443Z&X-Amz-Expires=43200&X-Amz-SignedHeaders=host&X-Amz-Signature=0965ca129cee49a41650df152057a17a4f9e265f92f2261a4f6576587272eb03","studio_link":"https://studio.reducto.ai/job/3f6ef64d-c949-4b8d-9898-afb3b01669e6","usage":{"num_pages":1,"credits":1.0,"credit_breakdown":{"page":1.0},"page_billing_breakdown":{"1":["page"]},"non_empty_cell_count":null},"result":{"type":"full","chunks":[{"content":"#
Test PDF File","embed":"# Test PDF File","enriched":null,"enrichment_success":false,"blocks":[{"type":"Title","bbox":{"left":0.16189574527182748,"top":0.09479295553814121,"width":0.11946290650820875,"height":0.02146414301710507,"page":1,"original_page":1},"content":"Test
PDF File","image_url":null,"chart_data":null,"confidence":"high","granular_confidence":{"extract_confidence":null,"parse_confidence":0.7185355693101882},"extra":null}]}],"ocr":{"words":[{"text":"Test","bbox":{"left":0.16189475464665032,"top":0.09491921434498797,"width":0.03832089043910207,"height":0.021019531018806225,"page":1,"original_page":1},"confidence":1.0,"chunk_index":null,"rotation":359},{"text":"PDF","bbox":{"left":0.20548195932425706,"top":0.09514990719881924,"width":0.03939929039649714,"height":0.02102524343163076,"page":1,"original_page":1},"confidence":1.0,"chunk_index":null,"rotation":359},{"text":"File","bbox":{"left":0.25014757642558977,"top":0.09538630283240115,"width":0.03177201514150582,"height":0.020984871218902895,"page":1,"original_page":1},"confidence":1.0,"chunk_index":null,"rotation":359}],"lines":[{"text":"Test
PDF File","bbox":{"left":0.16189475464665032,"top":0.09491921434498797,"width":0.12002483692044526,"height":0.021451959706316092,"page":1,"original_page":1},"confidence":1.0,"chunk_index":null,"rotation":359}]},"custom":null},"parse_mode":null,"document_properties":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:43 GMT
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:43.968997+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: reducto_v3
document:
document_url: data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg==
type: document_url
model: reducto/parse-v3
settings:
return_ocr_data: true
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,39 @@
interactions:
- request:
body: '{"input":"reducto://invalid-document-for-parity"}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/parse
response:
body:
string: '{"error":{"code":404,"name":"NOT_FOUND","message":"Document ''The file
may have expired or been deleted. Please re-upload and try again.'' not found"},"detail":"Document
''The file may have expired or been deleted. Please re-upload and try again.''
not found"}'
headers:
Content-Type:
- application/json
Date:
- Wed, 02 Sep 2026 01:14:02 GMT
status:
code: 404
message: ''
recorded_at: '2026-09-02T01:14:02.538070+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: reducto_v3
document:
document_url: reducto://invalid-document-for-parity
type: document_url
model: reducto/parse-v3
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,71 @@
interactions:
- request:
body: "--04abc28545d4b46a8ee703e56d88cc0c\r\nContent-Disposition: form-data; name=\"file\";
filename=\"document\"\r\nContent-Type: application/pdf\r\n\r\n%PDF-1.4\n1 0
obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n2 0 obj\n<< /Type /Pages /Kids
[3 0 R] /Count 1 >>\nendobj\n3 0 obj\n<< /Type /Page /Parent 2 0 R /Resources
4 0 R /MediaBox [0 0 612 792] /Contents 5 0 R >>\nendobj\n4 0 obj\n<< /Font
<< /F1 << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> >> >>\nendobj\n5
0 obj\n<< /Length 44 >>\nstream\nBT\n/F1 12 Tf\n100 700 Td\n(Test PDF File)
Tj\nET\nendstream\nendobj\nxref\n0 6\n0000000000 65535 f \n0000000009 00000
n \n0000000058 00000 n \n0000000115 00000 n \n0000000214 00000 n \n0000000293
00000 n \ntrailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n385\n%%EOF\n\r\n--04abc28545d4b46a8ee703e56d88cc0c--\r\n"
headers:
Accept:
- '*/*'
Content-Type:
- multipart/form-data; boundary=04abc28545d4b46a8ee703e56d88cc0c
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/upload
response:
body:
string: '{"file_id":"reducto://f3cc3c72-614a-4104-bb70-a516f37148e0.pdf","presigned_url":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:30 GMT
status:
code: 200
message: ''
- request:
body: '{"input":"reducto://f3cc3c72-614a-4104-bb70-a516f37148e0.pdf","formatting":{"table_output_format":"md"}}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/parse
response:
body:
string: '{"response_type":"parse","job_id":"aba924dc-7773-4dff-a4a8-3549366ea9fa","duration":4.5764172077178955,"pdf_url":"https://prod-storage20241010144745140900000001.s3.amazonaws.com/org/8bd983d1-47dd-440b-93d8-431412d819bf/f3cc3c72-614a-4104-bb70-a516f37148e0.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2UOK6OVBOUYL7WYA%2F20260901%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20260901T195435Z&X-Amz-Expires=43200&X-Amz-SignedHeaders=host&X-Amz-Signature=7d4c9464bb3a1a9d5c7a5f957bc10813fb16fcc6de3fea2054a40b469ffa79b3","studio_link":"https://studio.reducto.ai/job/aba924dc-7773-4dff-a4a8-3549366ea9fa","usage":{"num_pages":1,"credits":1.0,"credit_breakdown":{"page":1.0},"page_billing_breakdown":{"1":["page"]},"non_empty_cell_count":null},"result":{"type":"full","chunks":[{"content":"#
Test PDF File","embed":"# Test PDF File","enriched":null,"enrichment_success":false,"blocks":[{"type":"Title","bbox":{"left":0.16189574527182748,"top":0.09479295553814121,"width":0.11946290650820875,"height":0.02146414301710507,"page":1,"original_page":1},"content":"Test
PDF File","image_url":null,"chart_data":null,"confidence":"high","granular_confidence":{"extract_confidence":null,"parse_confidence":0.7185355693101882},"extra":null}]}],"ocr":null,"custom":null},"parse_mode":null,"document_properties":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:35 GMT
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:35.993066+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: reducto_v3
document:
document_url: data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg==
type: document_url
formatting:
table_output_format: md
model: reducto/parse-v3
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,69 @@
interactions:
- request:
body: "--b7daa0c5be8f80d33a4eb7a54318d93a\r\nContent-Disposition: form-data; name=\"file\";
filename=\"document\"\r\nContent-Type: application/pdf\r\n\r\n%PDF-1.4\n1 0
obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n2 0 obj\n<< /Type /Pages /Kids
[3 0 R] /Count 1 >>\nendobj\n3 0 obj\n<< /Type /Page /Parent 2 0 R /Resources
4 0 R /MediaBox [0 0 612 792] /Contents 5 0 R >>\nendobj\n4 0 obj\n<< /Font
<< /F1 << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> >> >>\nendobj\n5
0 obj\n<< /Length 44 >>\nstream\nBT\n/F1 12 Tf\n100 700 Td\n(Test PDF File)
Tj\nET\nendstream\nendobj\nxref\n0 6\n0000000000 65535 f \n0000000009 00000
n \n0000000058 00000 n \n0000000115 00000 n \n0000000214 00000 n \n0000000293
00000 n \ntrailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n385\n%%EOF\n\r\n--b7daa0c5be8f80d33a4eb7a54318d93a--\r\n"
headers:
Accept:
- '*/*'
Content-Type:
- multipart/form-data; boundary=b7daa0c5be8f80d33a4eb7a54318d93a
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/upload
response:
body:
string: '{"file_id":"reducto://010b01b2-83bd-446d-af11-d120c5ac2c02.pdf","presigned_url":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:27 GMT
status:
code: 200
message: ''
- request:
body: '{"input":"reducto://010b01b2-83bd-446d-af11-d120c5ac2c02.pdf"}'
headers:
Accept:
- '*/*'
Content-Type:
- application/json
User-Agent:
- litellm/1.101.0
method: POST
uri: http://parity-provider.invalid/parse
response:
body:
string: '{"response_type":"parse","job_id":"8138a6c6-b726-4300-90b4-e6d5d43f6f70","duration":1.2648272514343262,"pdf_url":"https://prod-storage20241010144745140900000001.s3.amazonaws.com/org/8bd983d1-47dd-440b-93d8-431412d819bf/010b01b2-83bd-446d-af11-d120c5ac2c02.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2UOK6OVBOUYL7WYA%2F20260901%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20260901T195428Z&X-Amz-Expires=43200&X-Amz-SignedHeaders=host&X-Amz-Signature=3cda9020fefff85d9dd13f124908d7b00e55b6e82a72039546d262099cfcf3b4","studio_link":"https://studio.reducto.ai/job/8138a6c6-b726-4300-90b4-e6d5d43f6f70","usage":{"num_pages":1,"credits":1.0,"credit_breakdown":{"page":1.0},"page_billing_breakdown":{"1":["page"]},"non_empty_cell_count":null},"result":{"type":"full","chunks":[{"content":"#
Test PDF File","embed":"# Test PDF File","enriched":null,"enrichment_success":false,"blocks":[{"type":"Title","bbox":{"left":0.16189574527182748,"top":0.09479295553814121,"width":0.11946290650820875,"height":0.02146414301710507,"page":1,"original_page":1},"content":"Test
PDF File","image_url":null,"chart_data":null,"confidence":"high","granular_confidence":{"extract_confidence":null,"parse_confidence":0.7185355693101882},"extra":null}]}],"ocr":null,"custom":null},"parse_mode":null,"document_properties":null}'
headers:
Content-Type:
- application/json
Date:
- Tue, 01 Sep 2026 19:54:29 GMT
status:
code: 200
message: ''
recorded_at: '2026-09-01T19:54:30.255600+00:00'
ttl_seconds: 0
version: 1
x-litellm:
case:
litellm_input:
contract: reducto_v3
document:
document_url: data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvUmVzb3VyY2VzIDQgMCBSIC9NZWRpYUJveCBbMCAwIDYxMiA3OTJdIC9Db250ZW50cyA1IDAgUiA+PgplbmRvYmoKNCAwIG9iago8PCAvRm9udCA8PCAvRjEgPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+ID4+ID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDQgPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihUZXN0IFBERiBGaWxlKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDIxNCAwMDAwMCBuIAowMDAwMDAwMjkzIDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKMzg1CiUlRU9GCg==
type: document_url
model: reducto/parse-v3
request_source: python_replay
schema_version: 1

View file

@ -0,0 +1,63 @@
from __future__ import annotations
import argparse
from pathlib import Path
from typing import Final, cast
import litellm
from litellm.rust_bridge.ocr import use_litellm_rust
from ......shared.parity.fixtures.recording import (
RecordedInteraction,
UpstreamEndpoint,
record_upstream_interactions,
)
from ......shared.parity.fixtures.store import FixtureEnvelope, read_fixture, save_fixture
from ......shared.parity.replay import replay_server
from .common import OcrSdkCall
from .config import configured_fixture_directory
from .models import OcrParityCase, OcrSdkInput
def _invoke(provider_url: str, case_input: OcrSdkInput) -> object:
sdk_call: Final = cast(OcrSdkCall, litellm.ocr)
return sdk_call(api_base=provider_url, api_key="test-key", **case_input.as_sdk_kwargs())
def migrate_fixture(path: Path) -> Path:
case: Final = read_fixture(path, OcrParityCase)
envelope: Final = FixtureEnvelope.model_validate_json(path.read_text(encoding="utf-8"))
with replay_server() as provider:
for response in case.provider_responses:
provider.enqueue_response(response)
captured: Final = record_upstream_interactions(UpstreamEndpoint(provider.url), case.litellm_input, _invoke)
provider.take_requests(len(case.provider_responses))
interactions: Final = tuple(
RecordedInteraction(item.request, response)
for item, response in zip(captured, case.provider_responses, strict=True)
)
destination: Final = save_fixture(
path.parent,
case.litellm_input,
case,
interactions,
recorded_at=envelope.recorded_at,
request_source="python_replay",
)
read_fixture(destination, OcrParityCase)
path.unlink()
return destination
def main() -> None:
parser: Final = argparse.ArgumentParser()
parser.add_argument("--fixture-dir", type=Path, default=configured_fixture_directory())
args: Final = parser.parse_args()
directory: Final = cast(Path, args.fixture_dir)
use_litellm_rust(False, ocr=None, aocr=None)
paths: Final = tuple(sorted(directory.rglob("*.json")))
for path in paths:
print(f"Migrated {path.name} to {migrate_fixture(path).name}")
if __name__ == "__main__":
main()

View file

@ -0,0 +1,259 @@
from __future__ import annotations
from collections.abc import Mapping
from typing import Final, Literal, cast
from hypothesis import strategies as st
from hypothesis.strategies import SearchStrategy
from pydantic import model_validator
from typing_extensions import Self
from ......shared.parity.fixtures.recording import UpstreamEndpoint
from .base import (
JsonSchemaResponseFormat,
OcrDocument,
OcrSdkInputBase,
)
from .common import (
OcrFixtureClient,
OcrRecordingTarget,
annotation_format,
document_transport_strategy,
invoke_with_api_key,
pdf_document,
)
MistralModel = Literal[
"mistral/mistral-ocr-3",
"mistral/mistral-ocr-3-0",
"mistral/mistral-ocr-2512",
"mistral/mistral-ocr-4-0",
"mistral/mistral-ocr-4-1",
"mistral/mistral-ocr-4",
"mistral/mistral-ocr-latest",
"mistral-ocr-3",
"mistral-ocr-3-0",
"mistral-ocr-2512",
"mistral-ocr-4-0",
"mistral-ocr-4-1",
"mistral-ocr-4",
"mistral-ocr-latest",
]
MistralFixtureModel = MistralModel | Literal["mistral/invalid-ocr-model-for-parity"]
MISTRAL_MODELS: Final[tuple[MistralModel, ...]] = (
"mistral/mistral-ocr-3",
"mistral/mistral-ocr-3-0",
"mistral/mistral-ocr-2512",
"mistral/mistral-ocr-4",
"mistral/mistral-ocr-4-0",
"mistral/mistral-ocr-4-1",
"mistral/mistral-ocr-latest",
)
class MistralCompatibleOcrSdkInput(OcrSdkInputBase):
document: OcrDocument
pages: str | list[int] | None = None
include_image_base64: bool | None = None
image_limit: int | None = None
image_min_size: int | None = None
bbox_annotation_format: JsonSchemaResponseFormat | None = None
document_annotation_format: JsonSchemaResponseFormat | None = None
document_annotation_prompt: str | None = None
extract_header: bool = False
extract_footer: bool = False
table_format: Literal["markdown", "html"] | None = None
confidence_scores_granularity: Literal["page", "word", "block"] | None = None
include_blocks: bool = True
id: str | None = None
@model_validator(mode="after")
def validate_annotation_prompt(self) -> Self:
if self.document_annotation_prompt is not None and self.document_annotation_format is None:
raise ValueError("document_annotation_prompt requires document_annotation_format")
return self
class MistralOcrSdkInput(MistralCompatibleOcrSdkInput):
contract: Literal["mistral"] = "mistral"
model: MistralFixtureModel
custom_llm_provider: Literal["mistral"] | None = None
@model_validator(mode="after")
def validate_provider_routing(self) -> Self:
if not self.model.startswith("mistral/") and self.custom_llm_provider != "mistral":
raise ValueError("unqualified Mistral models require custom_llm_provider='mistral'")
return self
MISTRAL_MODEL: Final[MistralModel] = "mistral/mistral-ocr-latest"
MISTRAL_PROVIDER_REJECTED_INPUTS: Final[tuple[MistralOcrSdkInput, ...]] = (
MistralOcrSdkInput(
model="mistral/invalid-ocr-model-for-parity",
document=pdf_document(),
),
)
MistralFeatureLevel = Literal["2505", "2512", "4"]
_MISTRAL_4_MODELS: Final = frozenset(
{
"mistral/mistral-ocr-4",
"mistral/mistral-ocr-4-0",
"mistral/mistral-ocr-4-1",
"mistral/mistral-ocr-latest",
}
)
_MISTRAL_2512_MODELS: Final = frozenset(
{*_MISTRAL_4_MODELS, "mistral/mistral-ocr-2512", "mistral/mistral-ocr-3", "mistral/mistral-ocr-3-0"}
)
def _feature_level(model: str) -> MistralFeatureLevel:
if model in _MISTRAL_4_MODELS:
return "4"
if model in _MISTRAL_2512_MODELS:
return "2512"
return "2505"
def _optional_param_strategies(
*,
include_document_annotation_prompt: bool = True,
) -> tuple[
tuple[SearchStrategy[dict[str, object]], ...],
tuple[SearchStrategy[dict[str, object]], ...],
tuple[SearchStrategy[dict[str, object]], ...],
]:
annotation: Final = annotation_format("document_title")
common: Final[tuple[SearchStrategy[dict[str, object]], ...]] = (
st.sampled_from(((0,), (0, 1))).map(list).map(lambda value: {"pages": value}),
st.sampled_from((False, True)).map(lambda value: {"include_image_base64": value}),
st.just({"image_limit": 1}),
st.just({"image_min_size": 300}),
st.just({"bbox_annotation_format": annotation_format("bounding_boxes")}),
st.just({"document_annotation_format": annotation}),
*(
(
st.just(
{
"document_annotation_format": annotation,
"document_annotation_prompt": "Extract the visible title",
}
),
)
if include_document_annotation_prompt
else ()
),
st.sampled_from(("page", "word")).map(lambda value: {"confidence_scores_granularity": value}),
)
feature_2512: Final[tuple[SearchStrategy[dict[str, object]], ...]] = (
st.sampled_from((False, True)).map(lambda value: {"extract_header": value}),
st.sampled_from((False, True)).map(lambda value: {"extract_footer": value}),
st.sampled_from(("markdown", "html")).map(lambda value: {"table_format": value}),
)
feature_4: Final[tuple[SearchStrategy[dict[str, object]], ...]] = (
st.just({"pages": "0-2"}),
st.sampled_from((False, True)).map(lambda value: {"include_blocks": value}),
st.just({"include_blocks": True, "confidence_scores_granularity": "block"}),
)
return common, feature_2512, feature_4
def mistral_optional_params_strategy(
feature_level: MistralFeatureLevel,
*,
include_document_annotation_prompt: bool = True,
) -> SearchStrategy[dict[str, object]]:
common, feature_2512, feature_4 = _optional_param_strategies(
include_document_annotation_prompt=include_document_annotation_prompt
)
return st.one_of(
*common,
*(feature_2512 if feature_level in {"2512", "4"} else ()),
*(feature_4 if feature_level == "4" else ()),
)
def _mistral_input_values(
document: OcrDocument,
optional_params: dict[str, object] | None = None,
) -> dict[str, object]:
return {"document": document, **(optional_params or {})}
def _mistral_input(
model: str,
document: OcrDocument,
optional_params: dict[str, object] | None = None,
) -> MistralOcrSdkInput:
return MistralOcrSdkInput.model_validate({"model": model, **_mistral_input_values(document, optional_params)})
def mistral_input_values_strategy(
feature_level: MistralFeatureLevel,
inline_image_data_uri: str,
*,
include_document_annotation_prompt: bool = True,
) -> SearchStrategy[dict[str, object]]:
option_document: Final = pdf_document()
return st.one_of(
document_transport_strategy(inline_image_data_uri).map(_mistral_input_values),
mistral_optional_params_strategy(
feature_level,
include_document_annotation_prompt=include_document_annotation_prompt,
).map(lambda optional_params: _mistral_input_values(option_document, optional_params)),
)
def mistral_input_strategy(
model: str,
inline_image_data_uri: str,
feature_level: MistralFeatureLevel | None = None,
) -> SearchStrategy[MistralOcrSdkInput]:
return mistral_input_values_strategy(feature_level or _feature_level(model), inline_image_data_uri).map(
lambda values: MistralOcrSdkInput.model_validate({"model": model, **values})
)
def _mistral_recording_strategy(inline_image_data_uri: str) -> SearchStrategy[MistralOcrSdkInput]:
document: Final = pdf_document()
baseline_models: Final = tuple(model for model in MISTRAL_MODELS if model != MISTRAL_MODEL)
common, feature_2512, feature_4 = _optional_param_strategies()
common_options: Final[SearchStrategy[dict[str, object]]] = st.one_of(*common)
feature_2512_options: Final[SearchStrategy[dict[str, object]]] = st.one_of(*feature_2512)
feature_4_options: Final[SearchStrategy[dict[str, object]]] = st.one_of(*feature_4)
return st.one_of(
st.sampled_from(baseline_models).map(lambda model: _mistral_input(model, document)),
document_transport_strategy(inline_image_data_uri).map(
lambda selected_document: _mistral_input(MISTRAL_MODEL, selected_document)
),
common_options.map(lambda optional_params: _mistral_input(MISTRAL_MODEL, document, optional_params)),
feature_2512_options.map(
lambda optional_params: _mistral_input("mistral/mistral-ocr-2512", document, optional_params)
),
feature_4_options.map(
lambda optional_params: _mistral_input("mistral/mistral-ocr-4-1", document, optional_params)
),
)
def mistral_recording_targets(
environ: Mapping[str, str], client: OcrFixtureClient, inline_image_data_uri: str
) -> tuple[OcrRecordingTarget, ...]:
api_key: Final = environ.get("MISTRAL_API_KEY")
if not api_key:
return ()
configured: Final = environ.get("MISTRAL_API_BASE", "https://api.mistral.ai").rstrip("/")
base_url: Final = configured.removesuffix("/v1")
return (
OcrRecordingTarget(
name="mistral-ocr",
upstream=UpstreamEndpoint(base_url=base_url),
strategy=cast(
SearchStrategy[OcrSdkInputBase],
_mistral_recording_strategy(inline_image_data_uri),
),
invocation=invoke_with_api_key(client, api_key),
required_inputs=MISTRAL_PROVIDER_REJECTED_INPUTS,
),
)

View file

@ -0,0 +1,71 @@
from __future__ import annotations
from collections.abc import Mapping
from typing import Annotated, Final, cast
from pydantic import Field, model_validator
from ......shared.parity.fixture_models import ParityCase
from .azure import (
AzureDocumentIntelligenceOcrSdkInput,
AzureMistralOcrSdkInput,
)
from .mistral import MistralOcrSdkInput
from .reducto import ReductoParseLegacySdkInput, ReductoParseV3SdkInput
from .vertex import VertexDeepSeekOcrSdkInput, VertexMistralOcrSdkInput
__all__ = ("OcrParityCase", "OcrSdkInput")
OcrSdkInput = Annotated[
MistralOcrSdkInput
| AzureMistralOcrSdkInput
| VertexMistralOcrSdkInput
| AzureDocumentIntelligenceOcrSdkInput
| VertexDeepSeekOcrSdkInput
| ReductoParseV3SdkInput
| ReductoParseLegacySdkInput,
Field(discriminator="contract"),
]
class OcrParityCase(ParityCase[OcrSdkInput]):
@model_validator(mode="before")
@classmethod
def load_legacy_contract(cls, value: object) -> object:
if not isinstance(value, Mapping):
return value
fixture: Final = cast(Mapping[str, object], value)
litellm_input: Final = fixture.get("litellm_input")
if not isinstance(litellm_input, Mapping) or "contract" in litellm_input:
return fixture
legacy_input: Final = cast(Mapping[str, object], litellm_input)
legacy_contract: Final = legacy_input.get("boundary")
if isinstance(legacy_contract, str):
return {
**fixture,
"litellm_input": {
"contract": legacy_contract,
**{key: item for key, item in legacy_input.items() if key != "boundary"},
},
}
model: Final = legacy_input.get("model")
if not isinstance(model, str):
return fixture
return {**fixture, "litellm_input": {"contract": _legacy_contract(model), **legacy_input}}
def _legacy_contract(model: str) -> str:
if model.startswith("azure_ai/doc-intelligence/"):
return "azure_document_intelligence"
if model.startswith("azure_ai/"):
return "azure_mistral"
if model.startswith("vertex_ai/deepseek"):
return "vertex_deepseek"
if model.startswith("vertex_ai/"):
return "vertex_mistral"
if model.endswith("parse-v3"):
return "reducto_v3"
if model.endswith("parse-legacy"):
return "reducto_legacy"
return "mistral"

View file

@ -0,0 +1,75 @@
from __future__ import annotations
import logging
import os
from collections.abc import Mapping
from typing import Final, cast
from dotenv import load_dotenv
import litellm
from litellm.rust_bridge.ocr import use_litellm_rust
from ......shared.parity.fixtures.cli import parse_recording_args
from ......shared.parity.fixtures.media import structured_image_data_uri
from ......shared.parity.fixtures.pipeline import record_fixtures
from ......shared.parity.fixtures.store import fixture_directory
from .azure import (
azure_document_intelligence_recording_targets,
azure_mistral_recording_targets,
)
from .base import OcrSdkInputBase
from .common import OcrFixtureClient, OcrRecordingTarget, OcrSdkCall
from .config import DEFAULT_FIXTURE_DIRECTORY, FIXTURE_DIR_ENV
from .mistral import mistral_recording_targets
from .models import OcrParityCase
from .reducto import reducto_recording_targets
from .vertex import vertex_recording_targets
class LiteLLMOcrFixtureClient:
def __init__(self, sdk_call: OcrSdkCall) -> None:
self.sdk_call: Final = sdk_call
def execute(self, api_base: str, api_key: str, case_input: OcrSdkInputBase) -> None:
self.sdk_call(api_base=api_base, api_key=api_key, **case_input.as_sdk_kwargs())
def discover_targets(
environ: Mapping[str, str],
client: OcrFixtureClient,
inline_image_data_uri: str,
) -> tuple[OcrRecordingTarget, ...]:
return (
*mistral_recording_targets(environ, client, inline_image_data_uri),
*azure_mistral_recording_targets(environ, client, inline_image_data_uri),
*azure_document_intelligence_recording_targets(environ, client),
*vertex_recording_targets(environ, client, inline_image_data_uri),
*reducto_recording_targets(environ, client, inline_image_data_uri),
)
def require_targets(targets: tuple[OcrRecordingTarget, ...]) -> tuple[OcrRecordingTarget, ...]:
if targets:
return targets
raise SystemExit("No OCR fixture providers are configured. Set a supported provider API key and endpoint")
def main() -> int:
logging.basicConfig(level=logging.INFO, format="%(message)s")
load_dotenv()
args: Final = parse_recording_args()
client: Final = LiteLLMOcrFixtureClient(cast(OcrSdkCall, litellm.ocr))
inline_image_data_uri: Final = structured_image_data_uri()
targets: Final = require_targets(discover_targets(os.environ, client, inline_image_data_uri))
root: Final = fixture_directory(
args.fixture_dir,
os.environ.get(FIXTURE_DIR_ENV),
DEFAULT_FIXTURE_DIRECTORY,
)
use_litellm_rust(False, ocr=None, aocr=None)
summary: Final = record_fixtures(targets, root, args.examples, args.concurrency, OcrParityCase)
return summary.exit_code
if __name__ == "__main__":
raise SystemExit(main())

View file

@ -0,0 +1,440 @@
from __future__ import annotations
import base64
import binascii
from collections.abc import Mapping
from typing import Annotated, Final, Literal, cast
from hypothesis import strategies as st
from hypothesis.strategies import SearchStrategy
from pydantic import Field, field_validator, model_validator
from typing_extensions import Self
from ......shared.parity.fixture_models import FixtureModel, JsonObject
from ......shared.parity.fixtures.media import structured_pdf_data_uri
from ......shared.parity.fixtures.recording import UpstreamEndpoint
from .base import OcrSdkInputBase
from .common import (
OcrFixtureClient,
OcrRecordingTarget,
image_data_document,
invoke_with_api_key,
)
def _validate_reducto_source(source: str) -> str:
if source.startswith("reducto://"):
return source
if not source.startswith("data:"):
raise ValueError("Reducto documents require a reducto:// id or base64 data URI")
try:
header, encoded = source.split(",", 1)
except ValueError as error:
raise ValueError("invalid Reducto data URI") from error
if ";base64" not in header:
raise ValueError("Reducto data URIs must be base64 encoded")
try:
base64.b64decode(encoded, validate=True)
except (binascii.Error, ValueError) as error:
raise ValueError("invalid Reducto base64 payload") from error
return source
class ReductoImageUrlDocument(FixtureModel):
type: Literal["image_url"]
image_url: str
@field_validator("image_url")
@classmethod
def validate_image_url(cls, value: str) -> str:
return _validate_reducto_source(value)
class ReductoDocumentUrlDocument(FixtureModel):
type: Literal["document_url"]
document_url: str
@field_validator("document_url")
@classmethod
def validate_document_url(cls, value: str) -> str:
return _validate_reducto_source(value)
ReductoDocument = Annotated[
ReductoImageUrlDocument | ReductoDocumentUrlDocument,
Field(discriminator="type"),
]
ReductoTableOutputFormat = Literal["html", "json", "md", "jsonbbox", "dynamic", "csv"]
ReductoReturnImage = Literal["figure", "table", "page"]
ReductoFormattingInclude = Literal[
"change_tracking",
"highlight",
"comments",
"hyperlinks",
"signatures",
"ignore_watermarks",
]
ReductoBlockType = Literal[
"Header",
"Footer",
"Title",
"Section Header",
"Page Number",
"List Item",
"Figure",
"Table",
"Key Value",
"Text",
"Comment",
"Signature",
]
_REDUCTO_FILTER_BLOCK_GROUPS: Final[tuple[tuple[ReductoBlockType, ...], ...]] = (
(),
("Header",),
("Header", "Footer", "Page Number"),
("Figure", "Table", "Key Value"),
)
_REDUCTO_RETURN_IMAGE_GROUPS: Final[tuple[tuple[ReductoReturnImage, ...], ...]] = (
(),
("figure",),
("table",),
("page",),
("figure", "table"),
)
class ReductoFormatting(FixtureModel):
add_page_markers: bool = False
table_output_format: ReductoTableOutputFormat = "dynamic"
merge_tables: bool = False
include: list[ReductoFormattingInclude] = Field(default_factory=list)
@field_validator("include")
@classmethod
def validate_unique_include(cls, value: list[ReductoFormattingInclude]) -> list[ReductoFormattingInclude]:
if len(value) != len(set(value)):
raise ValueError("formatting.include entries must be unique")
return value
class ReductoChunking(FixtureModel):
chunk_mode: Literal["variable", "section", "page", "disabled", "block", "page_sections"] = "disabled"
chunk_size: int | None = None
chunk_overlap: int = Field(default=0, ge=0)
@model_validator(mode="after")
def validate_chunking(self) -> Self:
if self.chunk_size is not None and self.chunk_size <= 0:
raise ValueError("chunk_size must be positive")
if self.chunk_size is not None and self.chunk_overlap >= self.chunk_size:
raise ValueError("chunk_overlap must be less than chunk_size")
return self
class ReductoRetrieval(FixtureModel):
chunking: ReductoChunking = Field(default_factory=ReductoChunking)
filter_blocks: list[ReductoBlockType] = Field(default_factory=list)
embedding_optimized: bool = False
@field_validator("filter_blocks")
@classmethod
def validate_unique_blocks(cls, value: list[ReductoBlockType]) -> list[ReductoBlockType]:
if len(value) != len(set(value)):
raise ValueError("retrieval.filter_blocks entries must be unique")
return value
class ReductoPageRange(FixtureModel):
start: int | None = Field(default=None, ge=1)
end: int | None = Field(default=None, ge=1)
@model_validator(mode="after")
def validate_range(self) -> Self:
if self.start is not None and self.end is not None and self.end < self.start:
raise ValueError("page range end must be greater than or equal to start")
return self
class ReductoTenantThrottling(FixtureModel):
tenant_id: str = Field(min_length=1, max_length=256)
max_share: float = Field(default=0.5, gt=0, le=1)
class ReductoHybridVpcSettings(FixtureModel):
environment: str | None = None
ReductoPageSelection = ReductoPageRange | list[ReductoPageRange] | list[int] | list[str]
ReductoV3Model = Literal["reducto/parse-v3", "parse-v3"]
ReductoLegacyModel = Literal["reducto/parse-legacy", "parse-legacy"]
_ReductoV3Route = Literal["qualified", "image", "unqualified"]
_ReductoLegacyRoute = Literal["qualified", "unqualified"]
REDUCTO_V3_MODELS: Final[tuple[Literal["reducto/parse-v3"], ...]] = ("reducto/parse-v3",)
REDUCTO_LEGACY_MODELS: Final[tuple[Literal["reducto/parse-legacy"], ...]] = ("reducto/parse-legacy",)
class ReductoSettings(FixtureModel):
model: Literal["r-1"] | None = None
ocr_system: Literal["standard", "legacy"] = "standard"
extraction_mode: Literal["ocr", "hybrid", "metadata"] = "hybrid"
force_url_result: bool = False
force_file_extension: str | None = None
return_ocr_data: bool = False
return_images: list[ReductoReturnImage] = Field(default_factory=list)
embed_pdf_metadata: bool = False
embed_pdf_metadata_dpi: int = Field(default=100, ge=50, le=250)
persist_results: bool = False
tenant_throttling: ReductoTenantThrottling | None = None
timeout: float | None = Field(default=None, gt=0)
page_range: ReductoPageSelection | None = None
document_password: str | None = None
hybrid_vpc: ReductoHybridVpcSettings = Field(default_factory=ReductoHybridVpcSettings)
@field_validator("return_images")
@classmethod
def validate_unique_images(cls, value: list[ReductoReturnImage]) -> list[ReductoReturnImage]:
if len(value) != len(set(value)):
raise ValueError("settings.return_images entries must be unique")
return value
class ReductoParseV3SdkInput(OcrSdkInputBase):
contract: Literal["reducto_v3"] = "reducto_v3"
model: ReductoV3Model
document: ReductoDocument
custom_llm_provider: Literal["reducto"] | None = None
formatting: ReductoFormatting = Field(default_factory=ReductoFormatting)
retrieval: ReductoRetrieval = Field(default_factory=ReductoRetrieval)
settings: ReductoSettings = Field(default_factory=ReductoSettings)
@model_validator(mode="after")
def validate_provider_routing(self) -> Self:
if self.model == "parse-v3" and self.custom_llm_provider != "reducto":
raise ValueError("unqualified Reducto models require custom_llm_provider='reducto'")
return self
class ReductoParseLegacySdkInput(OcrSdkInputBase):
contract: Literal["reducto_legacy"] = "reducto_legacy"
model: ReductoLegacyModel
document: ReductoDocument
custom_llm_provider: Literal["reducto"] | None = None
enhance: JsonObject | None = None
@model_validator(mode="after")
def validate_provider_routing(self) -> Self:
if self.model == "parse-legacy" and self.custom_llm_provider != "reducto":
raise ValueError("unqualified Reducto models require custom_llm_provider='reducto'")
return self
_REDUCTO_PROVIDER_REJECTED_DOCUMENT: Final = ReductoDocumentUrlDocument(
type="document_url",
document_url="reducto://invalid-document-for-parity",
)
REDUCTO_V3_PROVIDER_REJECTED_INPUTS: Final[tuple[ReductoParseV3SdkInput, ...]] = (
ReductoParseV3SdkInput(
model="reducto/parse-v3",
document=_REDUCTO_PROVIDER_REJECTED_DOCUMENT,
),
)
REDUCTO_LEGACY_PROVIDER_REJECTED_INPUTS: Final[tuple[ReductoParseLegacySdkInput, ...]] = (
ReductoParseLegacySdkInput(
model="reducto/parse-legacy",
document=_REDUCTO_PROVIDER_REJECTED_DOCUMENT,
),
)
_REDUCTO_API_BASE: Final = "https://platform.reducto.ai"
def _formatting_strategy() -> SearchStrategy[ReductoFormatting]:
values: Final = st.one_of(
st.sampled_from(("dynamic", "html", "md", "json", "csv", "jsonbbox")).map(
lambda value: {"table_output_format": value}
),
st.sampled_from((False, True)).map(lambda value: {"add_page_markers": value}),
st.sampled_from((False, True)).map(lambda value: {"merge_tables": value}),
st.sampled_from(
(
(),
("hyperlinks",),
("change_tracking", "highlight", "comments"),
("signatures", "ignore_watermarks"),
)
)
.map(list)
.map(lambda value: {"include": value}),
)
return values.map(ReductoFormatting.model_validate)
def _chunking_strategy() -> SearchStrategy[ReductoChunking]:
return st.one_of(
st.sampled_from(("disabled", "section", "page", "block", "page_sections")).map(
lambda mode: ReductoChunking(chunk_mode=mode)
),
st.just(ReductoChunking(chunk_mode="variable")),
st.sampled_from((250, 1000, 1500)).map(lambda size: ReductoChunking(chunk_mode="variable", chunk_size=size)),
st.sampled_from((32, 128)).map(
lambda overlap: ReductoChunking(chunk_mode="variable", chunk_size=1000, chunk_overlap=overlap)
),
)
def _retrieval_strategy() -> SearchStrategy[ReductoRetrieval]:
filter_blocks: Final = cast(
SearchStrategy[list[ReductoBlockType]],
st.sampled_from(_REDUCTO_FILTER_BLOCK_GROUPS).map(list),
)
return st.one_of(
_chunking_strategy().map(lambda chunking: ReductoRetrieval(chunking=chunking)),
filter_blocks.map(lambda selected_blocks: ReductoRetrieval(filter_blocks=selected_blocks)),
st.sampled_from((False, True)).map(
lambda optimized: ReductoRetrieval(
chunking=ReductoChunking(chunk_mode="variable"),
embedding_optimized=optimized,
)
),
)
def _settings_strategy() -> SearchStrategy[ReductoSettings]:
# force_url_result stays model-compatible but is not recorded until the
# response transform follows and downloads result.url.
return_images: Final[SearchStrategy[list[ReductoReturnImage]]] = st.sampled_from(_REDUCTO_RETURN_IMAGE_GROUPS).map(
list
)
page_ranges: Final = st.one_of(
st.just(ReductoPageRange(start=1, end=1)),
st.just(ReductoPageRange(start=1, end=3)),
st.sampled_from(
(
(
ReductoPageRange(start=1, end=2),
ReductoPageRange(start=4, end=5),
),
)
).map(list),
)
return st.one_of(
st.just(ReductoSettings(model="r-1")),
st.sampled_from(("standard", "legacy")).map(lambda value: ReductoSettings(ocr_system=value)),
st.sampled_from(("hybrid", "ocr", "metadata")).map(lambda value: ReductoSettings(extraction_mode=value)),
st.just(ReductoSettings(return_ocr_data=True)),
return_images.map(lambda selected_images: ReductoSettings(return_images=selected_images)),
st.just(ReductoSettings(embed_pdf_metadata=True)),
st.sampled_from((50, 100, 250)).map(
lambda dpi: ReductoSettings(embed_pdf_metadata=True, embed_pdf_metadata_dpi=dpi)
),
st.just(ReductoSettings(timeout=300.0)),
page_ranges.map(lambda page_range: ReductoSettings(page_range=page_range)),
)
def _reducto_v3_baseline(
route: _ReductoV3Route,
document: ReductoDocument,
inline_image_data_uri: str,
) -> ReductoParseV3SdkInput:
if route == "image":
inline_image: Final = ReductoImageUrlDocument.model_validate(
image_data_document(inline_image_data_uri).model_dump(mode="json")
)
return ReductoParseV3SdkInput(model="reducto/parse-v3", document=inline_image)
if route == "unqualified":
return ReductoParseV3SdkInput(
model="parse-v3",
custom_llm_provider="reducto",
document=document,
)
return ReductoParseV3SdkInput(model="reducto/parse-v3", document=document)
def reducto_v3_input_strategy(
inline_image_data_uri: str,
document: ReductoDocument | None = None,
) -> SearchStrategy[ReductoParseV3SdkInput]:
selected_document: Final = document or ReductoDocumentUrlDocument(
type="document_url", document_url="reducto://fixture-document.pdf"
)
baseline_routes: Final[tuple[_ReductoV3Route, ...]] = ("qualified", "image", "unqualified")
return st.one_of(
st.sampled_from(baseline_routes).map(
lambda route: _reducto_v3_baseline(route, selected_document, inline_image_data_uri)
),
_formatting_strategy().map(
lambda formatting: ReductoParseV3SdkInput(
model="reducto/parse-v3",
document=selected_document,
formatting=formatting,
)
),
_retrieval_strategy().map(
lambda retrieval: ReductoParseV3SdkInput(
model="reducto/parse-v3",
document=selected_document,
retrieval=retrieval,
)
),
_settings_strategy().map(
lambda settings: ReductoParseV3SdkInput(
model="reducto/parse-v3",
document=selected_document,
settings=settings,
)
),
)
def _reducto_legacy_input(
route: _ReductoLegacyRoute,
document: ReductoDocument,
) -> ReductoParseLegacySdkInput:
if route == "unqualified":
return ReductoParseLegacySdkInput(
model="parse-legacy",
custom_llm_provider="reducto",
document=document,
)
return ReductoParseLegacySdkInput(model="reducto/parse-legacy", document=document)
def reducto_legacy_input_strategy(
document: ReductoDocument | None = None,
) -> SearchStrategy[ReductoParseLegacySdkInput]:
selected_document: Final = document or ReductoDocumentUrlDocument(
type="document_url", document_url="reducto://fixture-document.pdf"
)
routes: Final[tuple[_ReductoLegacyRoute, ...]] = ("qualified", "unqualified")
return st.sampled_from(routes).map(lambda route: _reducto_legacy_input(route, selected_document))
def reducto_recording_targets(
environ: Mapping[str, str], client: OcrFixtureClient, inline_image_data_uri: str
) -> tuple[OcrRecordingTarget, ...]:
api_key: Final = environ.get("REDUCTO_API_KEY")
if not api_key:
return ()
base_url: Final = environ.get("REDUCTO_API_BASE", _REDUCTO_API_BASE).rstrip("/")
document: Final = ReductoDocumentUrlDocument(type="document_url", document_url=structured_pdf_data_uri())
invocation: Final = invoke_with_api_key(client, api_key)
return (
OcrRecordingTarget(
name="reducto-v3",
upstream=UpstreamEndpoint(base_url=base_url),
strategy=cast(SearchStrategy[OcrSdkInputBase], reducto_v3_input_strategy(inline_image_data_uri, document)),
invocation=invocation,
required_inputs=REDUCTO_V3_PROVIDER_REJECTED_INPUTS,
),
OcrRecordingTarget(
name="reducto-legacy",
upstream=UpstreamEndpoint(base_url=base_url),
strategy=cast(SearchStrategy[OcrSdkInputBase], reducto_legacy_input_strategy(document)),
invocation=invocation,
required_inputs=REDUCTO_LEGACY_PROVIDER_REJECTED_INPUTS,
),
)

View file

@ -0,0 +1,148 @@
from __future__ import annotations
from collections.abc import Mapping
from typing import Final, Literal, cast
from hypothesis import strategies as st
from hypothesis.strategies import DrawFn, SearchStrategy
from ......shared.parity.fixtures.recording import UpstreamEndpoint
from .base import OcrDocument, OcrSdkInputBase
from .common import (
OcrFixtureClient,
OcrRecordingTarget,
image_data_document,
invoke_with_api_key,
)
from .mistral import (
MistralCompatibleOcrSdkInput,
mistral_input_values_strategy,
)
VertexMistralModel = Literal["vertex_ai/mistral-ocr-2505"]
VertexDeepSeekModel = Literal["vertex_ai/deepseek-ai/deepseek-ocr-maas"]
VertexMistralFixtureModel = VertexMistralModel | Literal["vertex_ai/invalid-ocr-model-for-parity"]
VertexDeepSeekFixtureModel = VertexDeepSeekModel | Literal["vertex_ai/deepseek-ai/invalid-ocr-model-for-parity"]
VERTEX_MISTRAL_MODELS: Final[tuple[VertexMistralModel, ...]] = ("vertex_ai/mistral-ocr-2505",)
VERTEX_DEEPSEEK_MODELS: Final[tuple[VertexDeepSeekModel, ...]] = ("vertex_ai/deepseek-ai/deepseek-ocr-maas",)
class VertexMistralOcrSdkInput(MistralCompatibleOcrSdkInput):
contract: Literal["vertex_mistral"] = "vertex_mistral"
model: VertexMistralFixtureModel = "vertex_ai/mistral-ocr-2505"
custom_llm_provider: Literal["vertex_ai"] | None = None
vertex_project: str
vertex_location: str = "us-central1"
class VertexDeepSeekOcrSdkInput(OcrSdkInputBase):
contract: Literal["vertex_deepseek"] = "vertex_deepseek"
model: VertexDeepSeekFixtureModel = "vertex_ai/deepseek-ai/deepseek-ocr-maas"
document: OcrDocument
custom_llm_provider: Literal["vertex_ai"] | None = None
vertex_project: str
vertex_location: str = "us-central1"
def vertex_mistral_provider_rejected_inputs(
project: str,
location: str,
inline_image_data_uri: str,
) -> tuple[VertexMistralOcrSdkInput, ...]:
return (
VertexMistralOcrSdkInput(
model="vertex_ai/invalid-ocr-model-for-parity",
document=image_data_document(inline_image_data_uri),
vertex_project=project,
vertex_location=location,
),
)
def vertex_deepseek_provider_rejected_inputs(
project: str,
location: str,
inline_image_data_uri: str,
) -> tuple[VertexDeepSeekOcrSdkInput, ...]:
return (
VertexDeepSeekOcrSdkInput(
model="vertex_ai/deepseek-ai/invalid-ocr-model-for-parity",
document=image_data_document(inline_image_data_uri),
vertex_project=project,
vertex_location=location,
),
)
def _as_vertex_mistral(
values: dict[str, object],
project: str,
location: str,
model: VertexMistralModel,
) -> VertexMistralOcrSdkInput:
return VertexMistralOcrSdkInput.model_validate(
{**values, "model": model, "vertex_project": project, "vertex_location": location}
)
def vertex_mistral_input_strategy(
project: str,
location: str,
inline_image_data_uri: str,
) -> SearchStrategy[VertexMistralOcrSdkInput]:
return st.builds(
_as_vertex_mistral,
project=st.just(project),
location=st.just(location),
model=st.sampled_from(VERTEX_MISTRAL_MODELS),
values=mistral_input_values_strategy("2505", inline_image_data_uri),
)
@st.composite
def vertex_deepseek_input_strategy(
draw: DrawFn, project: str, location: str, inline_image_data_uri: str
) -> VertexDeepSeekOcrSdkInput:
return VertexDeepSeekOcrSdkInput.model_validate(
{
"model": draw(st.sampled_from(VERTEX_DEEPSEEK_MODELS)),
"document": image_data_document(inline_image_data_uri),
"vertex_project": project,
"vertex_location": location,
}
)
def vertex_recording_targets(
environ: Mapping[str, str], client: OcrFixtureClient, inline_image_data_uri: str
) -> tuple[OcrRecordingTarget, ...]:
api_key: Final = environ.get("VERTEX_AI_API_KEY")
project: Final = environ.get("VERTEXAI_PROJECT") or environ.get("VERTEX_PROJECT")
location: Final = environ.get("VERTEXAI_LOCATION") or environ.get("VERTEX_LOCATION") or "us-central1"
if not api_key or not project:
return ()
base_url: Final = environ.get("VERTEX_AI_API_BASE") or f"https://{location}-aiplatform.googleapis.com"
invocation: Final = invoke_with_api_key(client, api_key)
return (
OcrRecordingTarget(
name="vertex-mistral",
upstream=UpstreamEndpoint(base_url=base_url.rstrip("/")),
strategy=cast(
SearchStrategy[OcrSdkInputBase],
vertex_mistral_input_strategy(project, location, inline_image_data_uri),
),
invocation=invocation,
required_inputs=vertex_mistral_provider_rejected_inputs(project, location, inline_image_data_uri),
),
OcrRecordingTarget(
name="vertex-deepseek",
upstream=UpstreamEndpoint(base_url=base_url.rstrip("/")),
strategy=cast(
SearchStrategy[OcrSdkInputBase],
vertex_deepseek_input_strategy(project, location, inline_image_data_uri),
),
invocation=invocation,
required_inputs=vertex_deepseek_provider_rejected_inputs(project, location, inline_image_data_uri),
),
)

Some files were not shown because too many files have changed in this diff Show more