Judge API¶
The faithful judge interface for external evaluation harnesses: the prompt is sent VERBATIM (no persona, no scaffolding), nothing is cached, and every result carries its model id and prompt hash for auditability.
- async LayoutLens.judge(image_path, prompt, *, max_tokens=AUTO, timeout=120.0)[source]
Send
promptVERBATIM with an image and return a parsed verdict.This is the faithful judge interface for external evaluation harnesses (e.g. UIJudgeBench). Unlike
analyze(), LayoutLens adds NOTHING to the prompt: no system persona, no scaffolding, no appended JSON-format instruction. The caller owns the entire prompt, including any response contract. The call always hits the model (no caching) and honors the per-model parameter policy (Claude 4.6+/5 omit temperature).- Parameters:
image_path (str | Path) – Path to an existing image file (mime inferred from the extension:
.jpg/.jpeg-> JPEG, otherwise PNG).prompt (str) – The exact text to send as the sole text block.
max_tokens (int | _Auto) – Maximum tokens to generate. Defaults to
AUTO, which resolves to 8000 for reasoning/thinking models (they spend thinking tokens inside this budget) and 300 otherwise. Pass an explicit integer to override.timeout (float) – Per-call timeout in seconds (default 120 — reasoning models can take well over 30s on a single judgment).
- Returns:
JudgeResult with the parsed answer/confidence/rationale, the raw text, a refusal flag, per-model usage split, and the parse mode.
- Raises:
ValidationError – If
image_pathdoes not exist.AuthenticationError – If no API key is configured for a mapped provider.
- Return type:
- class layoutlens.JudgeResult(answer, confidence, rationale, raw, refused, usage, model, parse_mode, truncated=False, prompt_sha256='')[source]¶
Bases:
objectStructured outcome of a single
judge()call.- Parameters:
- usage¶
Token counts with keys prompt_tokens/completion_tokens/total_tokens; reasoning-capable backends may also report thought_tokens.
- truncated¶
True if the model stopped because it hit the token budget (
finish_reason == "length") — the verdict may be incomplete.- Type:
Batch Judging¶
- async LayoutLens.judge_batch(requests, *, max_tokens=AUTO, resume=True, manifest_path=None, poll_interval=10.0, poll_timeout=86400.0, reasoning_effort=None, image_detail='auto')[source]
Judge many image+prompt requests over a provider batch transport.
The batched counterpart to
judge(): each request sends its prompt VERBATIM with the same image bytes asjudge(), honors the reasoning-awaremax_tokensdefault and the per-model parameter policy, and is parsed into aJudgeResult. Batch APIs are ~50% cheaper and the right transport for bulk offline evaluation (e.g. UIJudgeBench). LayoutLens is thus the reference batched judge.The backend is chosen from an explicit provider/model combination:
provider="gemini"withgemini/*uses the google-genai inline batch (optional extralayoutlens[gemini]); native OpenAI uses the official Responses Batch API, and supported non-Gemini/non-OpenAI providers use the litellm file-based batch. All backends are resumable via a manifest.- Parameters:
requests (list[BatchRequest]) – The batch items. Each
idmust be unique and keys its result. A request whose image is missing yields an"unknown"result rather than aborting the batch.max_tokens (int | _Auto) – Per-request token budget. Defaults to
AUTO(8000 for reasoning models, else 300); an explicit integer overrides.resume (bool) – When True (default), collect any prior jobs from the manifest first and submit only uncovered ids. When False, the selected manifest path must not already exist.
manifest_path (str | Path | None) – Where submitted job ids persist for resume. Defaults to a content-addressed path under
output_dir/batchkeyed by the backend, endpoint, model, token budget, reasoning effort, image detail, exact prompts, image MIME types, and image bytes.poll_interval (float) – Seconds between batch-status polls.
poll_timeout (float) – Max seconds to wait for a single batch job.
reasoning_effort (str | None) – Native OpenAI reasoning effort.
Noneretains the model default; otherwise one ofnone,low,medium,high,xhigh, ormax. Rejected for other providers so a requested setting is never silently ignored.image_detail (str) – Native OpenAI image-detail setting:
auto,low,high, ororiginal. Non-default values are rejected for other providers.
- Returns:
{request_id: JudgeResult}for every request.- Raises:
AuthenticationError – If no API key is configured for a mapped provider.
ImportError – If a
gemini/*model is used withoutgoogle-genai.ValidationError – If request ids repeat or an existing resume manifest does not match the exact request.
- Return type:
- class layoutlens.BatchRequest(id, image_path, prompt)[source]¶
Bases:
objectOne item in a batch judge call.
- image_path¶
Path to the image to judge.
- Type: