Skip to content

refactor(v2): complete migration cleanup and typing coverage#2303

Merged
jxnl-oai merged 109 commits into
mainfrom
codex/v2-migration
May 17, 2026
Merged

refactor(v2): complete migration cleanup and typing coverage#2303
jxnl-oai merged 109 commits into
mainfrom
codex/v2-migration

Conversation

@jxnl-oai
Copy link
Copy Markdown
Collaborator

Summary

  • finish the v2 runtime ownership cleanup and provider dispatch refresh
  • tighten public sync/async inference across factories, response helpers, partial/parallel wrappers, and base-model helpers
  • document the v2 typing contract and expand executable typing coverage

Verification

  • UV_CACHE_DIR=/private/tmp/uv-cache uv run --with mypy mypy tests/typing/test_public_surface.py
  • UV_CACHE_DIR=/private/tmp/uv-cache uv run ty check instructor/v2/core/client.py instructor/v2/providers/litellm/client.py
  • UV_CACHE_DIR=/private/tmp/uv-cache uv run ruff check instructor/v2/core/client.py instructor/v2/providers/litellm/client.py tests/typing/test_public_surface.py
  • UV_CACHE_DIR=/private/tmp/uv-cache uv run pytest tests/v2/test_provider_specs.py tests/providers/test_auto_client.py::test_provider_dispatch_uses_registered_builder -q
  • UV_CACHE_DIR=/private/tmp/uv-cache uv run pytest tests/v2/test_provider_specs.py tests/providers/test_auto_client.py::test_provider_dispatch_uses_registered_builder tests/v2/test_provider_modes.py::test_anthropic_parallel_tools_extraction tests/v2/test_handlers_parametrized.py -q

jxnl and others added 30 commits January 18, 2026 13:40
- Add ModeRegistry for O(1) handler lookups via (Provider, Mode) tuples
- Add ModeHandler base class and protocol interfaces
- Add patch_v2() function for unified provider patching
- Add registry-based retry logic with handler integration
- Add exception hierarchy (RegistryError, ValidationContextError)
- Add mode normalization with deprecation warnings
- Add @register_mode_handler decorator for handler registration
- Add registry unit tests

This PR was written by [Cursor](https://cursor.com)
- Remove debug logging blocks in retry.py that wrote to hardcoded local path
- Fix GENAI_STRUCTURED_OUTPUTS enum value to avoid alias collision
- Fix sync retry to extract stream parameter from kwargs like async version
- Add docs/concepts/mode-migration.md explaining legacy mode deprecation
- Add tests/v2/test_mode_normalization.py for mode normalization logic
- Update mkdocs.yml with mode migration guide link
- Tests skip gracefully when handlers not yet registered

This PR was written by [Cursor](https://cursor.com)
- Fix tautological test assertion to verify handler exists
- Use provider-specific deprecated modes in warning test
- Add instructor/v2/providers/anthropic/ with handlers for TOOLS, JSON_SCHEMA, PARALLEL_TOOLS, ANTHROPIC_REASONING_TOOLS modes
- Add instructor/v2/providers/openai/ with handlers for TOOLS, JSON_SCHEMA, MD_JSON, PARALLEL_TOOLS, RESPONSES_TOOLS modes
- Update instructor/v2/__init__.py with from_anthropic and from_openai exports
- Update instructor/auto_client.py with v2 routing integration
- Add tests/v2/test_provider_modes.py for integration tests
- Add tests/v2/test_handlers_parametrized.py for unit tests
- Add tests/v2/test_openai_streaming.py for streaming tests

This PR was written by [Cursor](https://cursor.com)
- Remove debug logging in auto_client.py for Cohere client
- Fix google provider to use v1 from_genai (v2 not available yet)
- Add empty check for text_blocks in Anthropic MD_JSON handler
- Add None check for tool_calls in OpenAI PARALLEL_TOOLS handler
- Add instructor/v2/providers/genai/ with handlers for TOOLS, JSON modes
- Add instructor/v2/providers/cohere/ with handlers for TOOLS, JSON_SCHEMA, MD_JSON modes
- Add instructor/v2/providers/mistral/ with handlers for TOOLS, JSON_SCHEMA, MD_JSON modes
- Update instructor/v2/__init__.py with from_genai, from_cohere, from_mistral exports
- Add tests/v2/test_genai_integration.py
- Add tests/v2/test_cohere_handlers.py
- Add tests/v2/test_mistral_client.py and test_mistral_handlers.py

This PR was written by [Cursor](https://cursor.com)
- Remove debug logging in Cohere client
- Fix shallow copy mutation in Cohere handlers (copy messages list)
- Add empty list check in Mistral MD_JSON handler
…iter, Bedrock)

- Add instructor/v2/providers/xai/ with handlers for TOOLS, JSON_SCHEMA, MD_JSON modes
- Add instructor/v2/providers/groq/ with handlers for TOOLS, MD_JSON modes
- Add instructor/v2/providers/fireworks/ with handlers for TOOLS, MD_JSON modes
- Add instructor/v2/providers/cerebras/ with handlers for TOOLS, MD_JSON modes
- Add instructor/v2/providers/writer/ with handlers for TOOLS, MD_JSON modes
- Add instructor/v2/providers/bedrock/ with handlers for TOOLS, MD_JSON modes
- Update instructor/v2/__init__.py with all provider exports
- Add provider-specific test files for all 6 providers

All 11 v2 providers are now implemented.

This PR was written by [Cursor](https://cursor.com)
- Fix Bedrock MD_JSON handler to return early for None response_model
- Fix Fireworks async streaming to await the coroutine
- Fix xAI async streaming filter to only check for tool_calls
- Add fallback error handling for xAI sync streaming
- Add list content case to xAI MD_JSON handler
- Add truncated output detection to Writer handlers
Test reorganization:
- Move cache tests to tests/cache/
- Move core tests to tests/core/ (exceptions, patch, retry, schema)
- Move multimodal tests to tests/multimodal/
- Move processing tests to tests/processing/
- Move provider tests to tests/providers/
- Remove obsolete/duplicate test files

Unified test infrastructure:
- Add tests/v2/test_client_unified.py - Parametrized tests for all provider clients
- Add tests/v2/test_handler_registration_unified.py - Handler registration validation
- Add tests/v2/test_routing.py - Provider routing tests
- Add tests/v2/README.md - Test documentation
- Add tests/v2/UNIFICATION_OPPORTUNITIES.md - Future consolidation notes

This PR was written by [Cursor](https://cursor.com)
The test expects a deprecation warning that hasn't been added to v1 from_anthropic yet
Documentation:
- Add instructor/v2/README.md with comprehensive architecture documentation
- Update docs/modes-comparison.md with v2 mode mappings
- Update docs/integrations/anthropic.md, genai.md, google.md, bedrock.md
- Update docs/concepts/from_provider.md with v2 routing
- Update docs/api.md with v2 exports
- Update CLAUDE.md with v2 development notes

Code cleanup:
- Update pyproject.toml version
- Update .github/workflows/test.yml
- Minor fixes in instructor/core/, dsl/, processing/, providers/
- Remove obsolete plan/seo_plan.md

This PR was written by [Cursor](https://cursor.com)
Remove debug logging blocks that write to hardcoded local path
Fix non-deterministic test collection by sorting providers before parameterization
Remove debug logging blocks that write to hardcoded local path in prepare_request and parse_response methods
- Pass stream_extractor to Partial/Iterable streaming helpers (keep legacy fallback)

- Remove stray no-op import in vertexai shim

- Restore useful type info in openai_schema TypeError
Remove redundant handler files and register these providers directly
via OPENAI_COMPAT_PROVIDERS list. These providers use OpenAI-compatible
APIs, so they can share the same handler implementations.

- Add GROQ, FIREWORKS, CEREBRAS to OPENAI_COMPAT_PROVIDERS
- Update client imports to use OpenAI handlers module
- Update _HANDLER_SPECS to point to OpenAI handlers
- Remove redundant handler files (groq, fireworks, cerebras)
- Update registry to remove deleted handler modules
- Introduced `_parse_with_registry` to centralize parsing logic and handle deprecation warnings.
- Updated `ResponseSchema` methods for parsing Anthropic tools, JSON, OpenAI functions, and tools to use the new method.
- Deprecated `ResponseSchema.parse_*` methods in favor of `process_response` and `ResponseSchema.from_response` with core modes.
- Updated documentation to reflect the deprecation of legacy `ResponseSchema.parse_*` helpers.
…egistry

# Conflicts:
#	pyproject.toml
#	uv.lock
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 11, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
instructor 2e76cba Commit Preview URL

Branch Preview URL
May 17 2026, 05:27 AM

@jxnl-oai jxnl-oai force-pushed the codex/v2-migration branch from 893f1e1 to 0c926b1 Compare May 11, 2026 08:38
@jxnl-oai jxnl-oai enabled auto-merge (squash) May 17, 2026 05:32
@jxnl-oai jxnl-oai requested review from jxnl and vm May 17, 2026 05:32
@jxnl-oai jxnl-oai merged commit 60cc815 into main May 17, 2026
16 checks passed
@jxnl-oai jxnl-oai deleted the codex/v2-migration branch May 17, 2026 05:33
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.

3 participants