Skip to content

fix(batch): preserve Anthropic system messages - #2552

Closed
uczltw6 wants to merge 1 commit into
567-labs:mainfrom
uczltw6:codex/preserve-anthropic-batch-system-messages
Closed

uczltw6 wants to merge 1 commit into
567-labs:mainfrom
uczltw6:codex/preserve-anthropic-batch-system-messages

Conversation

@uczltw6

@uczltw6 uczltw6 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Describe your changes

BatchRequest.to_anthropic_format() previously overwrote system_message for every system turn, so Anthropic batch requests silently kept only the final instruction. This change combines every system message in order through the existing Anthropic helper, preserves both string and content-block forms, and continues to remove system turns from the provider messages list.

A regression test covers interleaved user and multiple system turns, and the fix is recorded in the unreleased changelog.

Issue ticket number and link

N/A — no matching issue or pull request was found.

Validation

  • uv run pytest tests/test_batch_processor_coverage.py tests/coverage/test_batch_openai_coverage.py tests/coverage/test_batch_anthropic_coverage.py tests/coverage/test_batch_api_coverage.py tests/test_batch_in_memory.py -q — 102 passed
  • uv run ruff check instructor/batch/request.py tests/coverage/test_batch_api_coverage.py — passed
  • uv run ruff format --check instructor/batch/request.py tests/coverage/test_batch_api_coverage.py — passed
  • uv run ty check instructor/batch/request.py tests/coverage/test_batch_api_coverage.py — passed

Checklist before requesting a review

  • I have performed a self-review of my code
  • If it is a core feature, I have added thorough tests.
  • If it is a core feature, I have added documentation.

OpenAI Codex assisted with the implementation and test preparation; the change was reviewed and verified with the commands above.

jxnl added a commit that referenced this pull request Aug 28, 2026
## Summary

- preserve every Anthropic batch system instruction during request
conversion
- reject AWS-documented unsupported Bedrock schema constraints locally
without misclassifying property names that resemble constraint keywords
- preserve caller-owned Bedrock nested inference configuration and
Gemini safety mappings during normalization
- preserve `TypedDict` `total=False`, `Required`, and `NotRequired`
semantics for top-level and iterable response models
- retry only failed live-provider tests once while keeping setup,
collection, repeated, and other failures red
- record the runtime and CI corrections in the `1.16.1` changelog

## Consolidated work

Supersedes #2530, #2532, #2551, #2552, and #2568. Closes #2567.

The original provider contributor commits and authors are preserved.
Follow-up coverage expands the Bedrock regression matrix across nested
schema paths, proves outgoing nested mappings are copied, and covers
mixed Anthropic system content. The TypedDict patch is consolidated
through one shared conversion helper; unlike #2568, it preserves
explicit `Required` keys inside `total=False` definitions and fixes the
iterable path as well.

## Validation

- exact head: `e1e59211e5e0a02fe49a2cc52c07060934512397` on
security-hardened main `000d893e2ece467d40e395f6ded37250dc732480`
- release validator and wheel smoke tests report `1.16.1` on Python 3.9
and 3.13
- 133 focused deterministic tests passed locally across response-model,
iterable, Bedrock, Gemini, batch, and remote-fetch interactions
- full statement and branch coverage gate passes; offline coverage
passes on Python 3.9-3.13
- Ruff lint/format and strict source/test `ty` checks pass
- the workflow YAML parses, its shell block passes syntax validation,
and `git diff --check` is clean
- the complete exact-head GitHub matrix is green, including every
configured provider suite and Workers
- the mixed-provider lane observed two provider-side Cohere 422
responses, reran exactly those two failed node IDs once, and both passed
- Codex Security full-range scan `ae875b7c-14cf-4dc7-a19f-91ad8f812786`
completed with no findings across seven runtime, schema, mutation, and
workflow surfaces
- Codex Security incremental scan `2e87410f-1846-497c-ad22-9317449c63cd`
completed with no findings on the final fail-closed workflow guard

## Intentionally separate

- #2557 remains open because official Google GenAI materials conflict on
function-response roles and the source PR has no provider-wire evidence
resolving the ambiguity
- OpenAI v3, async validators, Gemini tool-history conversion, Bedrock
bearer authentication, provider additions, dependency batches, and
architecture work remain outside this patch-sized consolidation
- Dependabot PRs #2570-#2575 remain separate because they are major
action updates or a broad Python dependency batch
- the documentation-only consolidation remains in #2565

TAC status was unavailable, so protected scan-output visibility could
not be verified; source coverage was complete.
@jxnl

jxnl commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Closing as consolidated by #2566, with mixed string/content-block system instructions and request immutability covered. Thank you for the contribution.

@jxnl jxnl closed this Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants