Repository navigation
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de924197fd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if self.provider_name == "anthropic" and "result" in data: | ||
| result = data["result"] | ||
| if result.get("type") == "error": | ||
| if result.get("type") in {"errored", "error"}: |
There was a problem hiding this comment.
Let error-only batches reach the new parser
When an ended Anthropic batch has no successes (for example, a one-item invalid request or a batch whose requests all share an invalid parameter), this branch is never reached through BatchProcessor.retrieve_results(): AnthropicProvider._iter_result_lines() still raises at instructor/batch/providers/anthropic.py:119-122 when errored > 0 and succeeded == 0, before calling batches_client.results(). Consequently the error-only cases covered by the new direct-parser test still produce a generic exception in the normal retrieval flow instead of the provider type and message; allow the result stream to be fetched and cover that retrieval path.
Useful? React with 👍 / 👎.
## Scope Current candidate: **68f4e4e1211e7672463ae76495bade22f8c41c17**. All 29 runnable current-head checks passed; publication skipped. Independent review found a recursive-schema crash in f4d7424; it was fixed and independently re-reviewed at 93a913e. The external autofix then added one more regression test in two commits; the runtime tree is unchanged. That test-only delta has also been independently reviewed with no actionable findings. Required approving GitHub review requested from `vm` remains the sole merge blocker. Publication remains explicitly on hold. The user additionally selected batch strict-schema and failed-result retrieval fixes. OpenAI schemas now require defaulted/nested fields, normalize references/compositions, preserve aliases and metadata, and do not mutate caller-owned schemas. Arbitrary-key mappings raise an explicit error instead of silently losing their value schema; Anthropic mappings are unchanged. Boolean-schema preservation is compatibility behavior, not proof that OpenAI accepts every custom schema. Completed OpenAI retrieval includes both output and error files, waits for files indicated by request counts, and supports error-only batches. With unknown counts it reads announced files without claiming their completeness. Ended Anthropic batches return failed request records even when none succeeded. Provider error type/message, request IDs and original records are preserved. Running jobs remain unavailable. Added native SDK/localhost retrieve-download contracts without new mocks or paid requests. ## Current Validation - Entire 25-file independent review found one P2: recursive described references could create a cyclic dictionary and raise RecursionError. Self-recursive and mutually recursive tests reproduced the failure before the fix. Copied reference nodes and path-local active references now preserve recursive back-references, metadata and strictness without cycles. The generated schemas validate nested instances with Draft 2020-12 validation. - Independent re-review verified the immutable 93a913e patch and found no remaining actionable issue. 457 tests passed during the whole-diff review at f4d7424; 78 focused tests passed after the repair. This engineering review cannot substitute for the required independent GitHub approval. - The final test-only delta was independently reviewed at immutable 68f4e4e; all 19 schema cases passed. All **43 batch regressions pass against the runtime-identical 93a913e installed wheel** on Python 3.9/OpenAI 2.0/Pydantic 2.8 and Python 3.13/OpenAI 3.3/Pydantic 2.14. That wheel was built from sdist and passed Twine checks without uploading. - [Final exact-head full coverage CI](https://github.com/567-labs/instructor/actions/runs/38118982055) passed **4,140 tests, 200 skipped, 862 deselected**, 106 existing warnings. It independently reports zero missing of 9,906 statements and four missing of 3,514 branches; the unchanged 99% gate and zero-missing assertion passed. Local runtime-identical 93a913e validation separately passed 4,139 tests with **99.9702% coverage**. No old-head CI is reused. - All 29 runnable final-head checks passed, including source/test typing, lint, Python 3.9-3.13 offline coverage, wheel matrix and provider jobs. [Current-head release-readiness CI](https://github.com/567-labs/instructor/actions/runs/38118982058) passed artifact preparation and Python 3.9/3.13 wheel smoke; publication was skipped. Provider success badges do not certify skipped live scenarios. - Checkout and final diff are clean; all 25 files are maintained code, tests, docs or changelog. No ad hoc reports or task plans are included. - The matching old-head Bugbot finding is addressed in [this review thread](#2767 (comment)) and resolved after test-backed independent verification. Requested maintainer approval must cover the current head, not f4d7424. No admin waiver applies to this PR. ## Prior Validation At f4d7424 - Final frozen-file combined offline suite: **4,137 passed, 200 skipped, 862 deselected**, 106 existing warnings, with CI mode, dotenv disabled and API_KEY environment variables removed (374.22 seconds). - **9,906 statements, zero missing; 3,514 branches, four missing; 99.9702% combined coverage.** The unchanged 99% gate and zero-missing-statement assertion passed. The initial run overlapped final schema edits and is not used as coverage proof; a fresh separate-database run produced these final totals. - Full source and test typing, Ruff lint/format checks, normal commit hooks and clean diff passed. - Final MkDocs build passed with existing nav/docstring warnings; wheel built from sdist, and both Twine checks passed. - **40 new batch regressions passed against the installed final wheel in each environment:** Python 3.9/OpenAI 2.0/Pydantic 2.8 and Python 3.13/OpenAI 3.3/Pydantic 2.14. Site-packages imports verified, not source-checkout imports. Prior 95-case installed-wheel proof belongs to 7ca0073. - Common provider finalization/regression suite: 215 passed; falsey adapter matrix rerun passed all 28 cases after test typing refinement. - Independent read-only re-review of the new batch fixes, generated TypedDict serializer and inherited finalizer found no actionable finding. Review did not itself run tests and does not constitute GitHub approval. Nested TypedDict-with-optional-key and direct provider-entry-point matrix extensions remain additional coverage opportunities; existing broad provider suites are separately validated. - Independent final read-only batch review found no remaining actionable issue after reference normalization and readiness/JSONL test gaps were addressed. This does not constitute GitHub approval. - All **29 runnable exact-head CI checks passed**; publication skipped. [Full coverage CI](https://github.com/567-labs/instructor/actions/runs/38092004959) independently confirms 4,137 passed, 200 skipped, 862 deselected and zero missing statements. [Release-readiness CI](https://github.com/567-labs/instructor/actions/runs/38092004970) passed preparation and wheel smoke tests without publishing. Provider job success is not a claim that every live provider scenario ran; for example, Google core-provider tests were skipped for missing settings. - Initial independent GitHub review request sent to `vm` with [exact-head evidence](#2767 (comment)), then updated to corrected head 93a913e in the addressed review thread above. Do not treat approval of the old head as approval of the fix. ## Production-Wide Simplicity Review Inspected all 205 production Python files across provider implementations, core/DSL/validation, public/legacy/batch/CLI, Decisions, and root integration. This is an implementation/maintainability review with targeted regression validation, not exhaustive security certification or universal live-provider proof. - Consolidated four identical OpenAI/Anthropic/Mistral/xAI result finalizers into the existing ModeHandler base. Preserve SDK-specific parsing, iterator laziness, falsey adapters, and exact raw-response identity; old imported module names remain explicit compatibility exports. Added a common four-provider behavioral matrix. - Reproduced and repaired missing Anthropic tool input being accepted as a defaulted empty result. Explicit returned empty objects still work. - Reproduced and repaired request-ID/metadata loss on invalid non-object batch payloads. - Reproduced and repaired underscore TypedDict cache misses and optional-key omission loss. Generated TypedDict models use narrowly scoped round-trip serialization; arbitrary user-model alias behavior is untouched. - Kept compatibility facades, provider wire/SDK exceptions, security limits, and streaming transport paths intact. Strict-schema and failed-batch retrieval findings are now fixed with user authorization. Streaming validation, native xAI context, CLI and registry-capability issues remain focused follow-ups, not silently folded into this patch. Integrate the five user-selected compact fixes onto main after #2708, retaining version 1.18.0. Publication is explicitly on hold. - [#2743](#2743) at 5c03dfd: validate complete batch payloads with Pydantic, including RootModel and empty objects with defaults. - [#2758](#2758) at 13a11f4: retain Anthropic errored result type/message, custom ID and raw record; preserve legacy error handling. - [#2757](#2757) at 3156d55: preserve underscore-prefixed TypedDict keys with collision-safe internal fields and original aliases. - [#2764](#2764) at ab9b0c2: replace nonfunctional logging environment instructions and unsupported correlation-ID claims. - [#2765](#2765) at faae38e: use the public Maybe model factory instead of nonexistent field APIs. The batch processor overlap is reconciled against merged main 035c77b. Release notes are consolidated under 1.18 rather than separate Unreleased sections. Dynamic TypedDict test construction and prepared-model narrowing were repaired for the full test typing gate, without weakening assertions. ## Prior Validation Candidate head: 128cf44. - Focused combined regressions and Decisions contracts: 341 passed, 1 existing skip. - Full source and test typing passed; repository Ruff lint/format checks and normal commit hooks passed. - Full MkDocs build passed with existing navigation/docstring warnings. - Wheel built from sdist; Twine checks passed for both distributions. - All 47 new batch/TypedDict regression cases passed against the installed wheel on Python 3.9 with OpenAI 2.0.0/Pydantic 2.8.0 and Python 3.13 with current core dependencies. Imports were verified to use site-packages, not the checkout. - Release metadata/notes validation passed for 1.18.0. - Exact-head remote full offline suite: 4,057 passed, 200 skipped, 862 deselected; zero missing statements and four missing branches. The unchanged 99% coverage gate passed. - All 29 runnable exact-head CI checks passed, including Python 3.9-3.13 coverage, lint/type checks, wheel matrix, and release readiness/smoke tests. Publication was skipped. Independent approval remains required; this PR stays draft while the user-requested production-wide simplicity review is ongoing. The initial local full-suite invocation inherited provider keys and lacked INSTRUCTOR_ENV=CI; it unexpectedly selected unmarked provider tests and was stopped after 1,286 passes/15 skips. It is not complete offline validation and is not used as a release gate. The corrected full coverage run uses the repository's CI mode with API keys removed. No intentional paid-provider experiments were added. No new mocks, threshold changes, tags, issue closures or publication. All 25 final files are maintained code, tests, docs or changelog; no ad hoc reports/task plans are included. Source PRs are credited without automatic issue-closing keywords.
Describe your changes
Anthropic's batch SDK serializes failed requests with
result.type="errored".BatchProcessorcurrently recognizes only"error", so these records becomeBatchError(error_type="extraction_error", error_message="Unknown error")even though the provider supplied a specific error.Recognize
"errored"while retaining the existing"error"handling. This preserves the provider's error type and message, custom request ID (custom_id), and raw record. Successful results remain unchanged.Three regression cases fail before the fix and pass afterward. They cover invalid-request and rate-limit records serialized by Anthropic SDK models, plus a mixed batch with a successful record. A fourth case preserves the existing
"error"record handling. The new tests exercise the public parser without mocking.Validation on Windows with Python 3.12.14 and Anthropic 0.93.0: 107 batch tests pass; Ruff lint/format checks and focused ty checks pass. No live provider requests were made.
The SDK's result discriminator is defined in MessageBatchErroredResult.
Issue ticket number and link
No existing issue found.
Checklist before requesting a review
This is a correction to existing batch error parsing and does not add a feature.