97e91a83f3
Ruff / Ruff (push) Waiting to run
Test / Core Tests (push) Waiting to run
Test / Offline Coverage Tests (Python 3.10) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.11) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.12) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.13) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.9) (push) Waiting to run
Test / Full Coverage (Python 3.11) (push) Waiting to run
Test / Core Provider Tests (OpenAI) (push) Blocked by required conditions
Test / Core Provider Tests (Anthropic) (push) Blocked by required conditions
Test / Core Provider Tests (Google) (push) Blocked by required conditions
Test / Core Provider Tests (Other) (push) Blocked by required conditions
Test / Anthropic Tests (push) Blocked by required conditions
Test / Gemini Tests (push) Blocked by required conditions
Test / Google GenAI Tests (push) Blocked by required conditions
Test / Vertex AI Tests (push) Blocked by required conditions
Test / OpenAI Tests (push) Blocked by required conditions
Test / Writer Tests (push) Blocked by required conditions
Test / Auto Client Tests (push) Blocked by required conditions
ty / type-check (push) Waiting to run
20 KiB
20 KiB
Changelog
All notable changes to instructor are documented here.
Format: Keep a Changelog Versioning: Semantic Versioning
[Unreleased]
Fixed
- Mistral/Vertex AI partial streaming: Avoid forwarding iterable-only parser arguments into completed
Partialresponses, preventing final Pydantic validation errors for sync and async streams. - Batch providers: Handle missing optional SDKs safely, validate OpenAI batch input before client setup, report exhausted output-file retries clearly, and remove unreachable fallbacks.
- OpenAI/Writer tools: Raise clear response-parsing errors for completions with no choices or tool calls instead of leaking attribute and index errors.
- Fireworks streaming: Keep non-streaming async calls non-streaming and return streaming async generators without incorrectly awaiting them.
- GenAI uploads: Respect
max_retries=0without an unwanted sleep or polling request, allow recovery on the final permitted retry, and report nameless pending uploads clearly before polling. - Gemini/GenAI messages: Honor an explicit system message for unstructured requests, remove the unsupported raw
systemargument, and reject invalid scalar message content clearly. - Templating: Use populated
contentswhenmessagesis empty, avoid mutating nested caller input, and preserve uncopyable metadata during template expansion. - Anthropic system messages: Reject invalid new system-message values even when no existing system message is present.
- Python 3.9: Include the required type-evaluation backport in minimal installs, keep overload metadata available, and avoid runtime evaluation of unsupported union syntax in the core response path and offline tests.
Tests / CI
- Coverage and test quality: Run the complete offline suite on Python 3.9-3.13, enforce fork-safe statement and branch coverage plus supported-version type checks in pull-request CI, add strict resource and thread warning checks, and provide a manual retry-mutation workflow. Consolidate typed response, stream, and SDK fixtures; remove duplicate tests and unreachable provider paths; and replace coverage-only stubs with meaningful edge-case and transport-backed provider checks.
[1.15.5] - 2026-06-28
Fixed
- v2 imports: Defer OpenAI SDK imports from core v2 modules until an OpenAI-specific path actually needs them, reducing import side effects for non-OpenAI usage. (#2390)
- v2 response models: Treat
list[A | B]PEP 604 unions of Pydantic models as iterable response models, matchinglist[Union[A, B]]schema behavior. (#2377) - OpenAI Responses API: Align
RESPONSES_TOOLStext.formatwith the forced tool schema and add targeted retry guidance when tool calls return empty{}arguments. (#2300, #2304)
[1.15.4] - 2026-06-27
Fixed
- CLI fine-tuning: Use the uploaded validation file ID when creating a fine-tuning job from local files, instead of passing the local validation file path through to OpenAI. (#2397)
- v2 core: Prepare list and primitive response models before provider handler dispatch, fixing
list[Model]and scalar response-model crashes such asAttributeError: type object 'list' has no attribute 'model_json_schema'. (#2374) - v2 streaming: Preserve backticks inside JSON string values during streamed JSON extraction.
- v2 multimodal: Accept raw bytes in
Image.autodetect()for JPEG, PNG, GIF, and WebP, while raising clear errors for unsupported image inputs. (#2344) - Docs: Refresh stale OpenAI and Ollama model strings in documentation examples. (#2395)
[1.15.3] - 2026-06-15
Fixed
- Bedrock: Route
top_k/topKthroughadditionalModelRequestFieldsinstead of leaving it as a top-level Converse kwarg. AWSInferenceConfigurationonly supportsmaxTokens/stopSequences/temperature/topP, so a leftovertop_kreachedclient.converse(top_k=...)and boto3 raisedParamValidationError: Unknown parameter "top_k". - Gemini/GenAI: Fold
generation_config(andsafety_settings/thinking_config) intoconfigwhenresponse_model=None, so plain-text calls no longer raisegenerate_content() got an unexpected keyword argument 'generation_config'(#2366). - v2 cleanup: Consolidate small provider/runtime fixes for Gemini JSON prompts, Cohere templating, JSON array extraction, iterable streaming, missing
jsonrefdependency guidance, retry semantics and hook metadata, and multimodal autodetection.
Tests / CI
- Type checking: Upgrade to
ty0.0.44, enforce warning-free checks with GitHub annotations, cover V2 tests, validate supported Python versions and platforms, and strengthen installed-package public API typing tests.
[1.15.2] - 2026-05-10
Security
- Logging: Redact sensitive request fields from debug logs, including nested auth headers such as
Authorizationandx-api-key. (#2297)
Fixed
- Templating (GenAI/VertexAI):
process_messageno longer crashes withTypeError: Can't compile non template nodeswhen multimodal messages contain image/URI/bytes Parts alongsidevalidation_context. Non-text Parts (wherepart.textisNone) now pass through unchanged. (#2253) - Retry:
IncompleteOutputExceptionnow propagates directly to the caller without being wrapped inInstructorRetryException, makingexcept IncompleteOutputExceptioncatch blocks work as documented. Applies to both sync and async paths. (#2273) - Anthropic/Bedrock: Omit
Nonefields from Anthropic tool-use retry payloads so Bedrock reasks no longer fail with HTTP 400 whencaller=None. (#2301) - Responses streaming: Surface reasoning-summary events in
RESPONSES_TOOLSpartial streaming and await callback return values when they are awaitable. (#2299)
[1.15.1] - 2026-04-03
Security
- Bedrock: Block remote HTTP(S) image URL fetching in
_openai_image_part_to_bedrock— onlydata:URLs are now accepted, preventing SSRF via user-controlled image URLs - Bedrock/PDF: Block remote URL and local file fetching in
PDF.to_bedrock— only base64 data ors3://sources are now supported, preventing SSRF and local file disclosure
Added
- Hooks:
completion:errorandcompletion:last_attempthandlers now receiveattempt_number,max_attempts, andis_last_attemptas keyword arguments. Old-style handlers remain fully backward-compatible. - Anthropic:
from_provider("anthropic/...")now sets aUser-Agent: instructor/<version>header on the Anthropic client
Fixed
- Anthropic usage: Initialize usage correctly for
ANTHROPIC_REASONING_TOOLSandANTHROPIC_PARALLEL_TOOLSmodes — previously fell through to OpenAI usage tracking with wrong field names - OpenRouter: Use
reask_md_jsonforOPENROUTER_STRUCTURED_OUTPUTSretries instead ofreask_default(tool-call format), fixing malformed retry prompts - Templating: Return
kwargsunchanged instead ofNoneinhandle_templatingwhen message list is empty or format is unrecognized;process_messagealso now returns the original message unchanged for unrecognized formats instead ofNone from_openai: AllowMode.JSON_SCHEMAfor the OpenAI provider — it was incorrectly blocked by the mode validation check- Bedrock: Pass through
cachePointdicts in message content unchanged — previously raisedValueError: Unsupported dict content for Bedrock, breaking prompt caching (regression since v1.13.0) - Bedrock: Allow
Mode.MD_JSONinfrom_bedrock - Parallel tools:
ParallelBasegenerator now consumed intoListResponsein both sync and async paths, fixingAttributeErrorwhen setting_raw_responseon a generator
[1.15.0] - 2026-04-02
Security
- Pin litellm to
<=1.82.6to block compromised versions 1.82.7 and 1.82.8 (#2219) - Make
diskcachean optional dependency, removing it from all users' transitive dependency trees and mitigating CVE-2025-69872 (#2211)
Fixed
- Usage tracking: Preserve
response.usagesubclass type (e.g. LiteLLM, Langfuse) when accumulating token counts across retries — fixes downstream.get()method loss (#2217, #2199) - Gemini: Exclude
HARM_CATEGORY_IMAGE_*safety categories from standard Gemini API calls — these are Vertex AI-only and caused400 INVALID_ARGUMENTerrors (#2174) - Gemini: Detect truncated responses (
finish_reason=MAX_TOKENS) inGENAI_STRUCTURED_OUTPUTSmode and raiseIncompleteOutputExceptionimmediately instead of retrying with malformed JSON (#2232) create_with_completion: HandleList[Model]response models that lack_raw_responseattribute — previously raisedAttributeError, now returnsNonefor the completion (#2167)- Partial streaming: Preserve default
Literalfield values (e.g.type: Literal["Person"] = "Person") during streaming instead of emittingNonebefore the field arrives (#2204) - Partial streaming: Support PEP 604 union syntax (
str | int) inPartialmodels on Python 3.10+ (#2200) - Validators: Fix
allow_override=Trueinllm_validator— the override branch was unreachable due to a misplaced assertion, sofixed_valuewas never returned (#2215) - Parallel tools:
ParallelBaseresponses now returnListResponse(consistent withIterableBase) instead of a raw generator with_raw_responseset on it (#2216) - Multimodal: Add missing
continueinconvert_messagesafter handling typed (audio/image) messages — previously fell through tomessage["role"]causingKeyError(#2139) - Anthropic: Fix dead code path for
ANTHROPIC_REASONING_TOOLSmode — the mode was shadowed by a duplicateANTHROPIC_TOOLScheck and never routed correctly (#2140)
Added
- Models: Add Claude 4 (Opus, Sonnet, Haiku), OpenAI GPT-4.1 series, o3/o4 reasoning models, xAI Grok 3, and DeepSeek R1/V3 to
KnownModelNametype (#2235)
Docs
- Update GitHub organization links in README from
instructor-aito567-labs(#2149)
Tests / CI
- Fix
test_xai_optional_dependencytests to usemonkeypatchso they pass regardless of whetherxai-sdkis installed - Update deprecated Anthropic model names (
claude-3-5-haiku-latest->claude-haiku-4-0-20250414,claude-3-7-sonnet-latest->claude-sonnet-4-5-20250514) - Update deprecated OpenAI model names (
gpt-3.5-turbo->gpt-4.1-mini) across unit tests - Update stale provider model strings in
shared_config.py: Writer palmyra-x5, Fireworks llama-v3p3, Perplexity sonar-pro
[1.14.5] - 2026-01-29
Fixed
- Google GenAI:
thought_signatureis now preserved across validation retries for thinking models (#2001) - Metadata:
pyproject.tomlauthor field corrected so PyPI correctly populates theAuthorfield (#2015) - Deps: Dev dependencies moved to the correct
[dependency-groups]section inpyproject.toml(#2030)
[1.14.4] - 2026-01-16
Fixed
- Responses API: Validation errors during structured output parsing are now caught and retried correctly (#2002)
- Google GenAI: User-provided
GenerationConfiglabels and custom fields are no longer silently dropped when merging configs (#2005) - Google GenAI:
SafetySettingsnow applied correctly when request contains image content (#2007) - List responses: Response wrappers no longer crash on attribute-style access (#2011)
_raw_response: Attribute access on list response wrappers works correctly (#2012)
Changed
json_tracker: Sibling-heuristic algorithm simplified for improved partial-streaming reliability (#2000)
[1.14.3] - 2026-01-13
Added
- Partial streaming: Completeness-based streaming validation — fields are validated progressively rather than failing mid-stream (#1999)
Fixed
- Streaming reask:
Streamobjects in reask handlers are now consumed correctly before retry, preventing stale-stream errors (#1992)
[1.14.2] - 2026-01-13
Fixed
- Partial streaming: Model validators now skip during partial streaming and run only once on the final complete object, preventing spurious errors (#1994)
- Partial: Infinite recursion with self-referential models (e.g.
TreeNodewithchildren: List["TreeNode"]) is now prevented (#1997)
Tests / CI
- Provider tests skipped in CI when API secrets are not available (#1990)
[1.14.1] - 2026-01-08
Fixed
- Google GenAI:
cached_contentparameter now correctly forwarded to support Google context caching (#1987)
[1.14.0] - 2026-01-04
Added
- Bedrock: Document support — pass PDFs and text files directly to Bedrock models (#1936)
Fixed
from_provider(): Now respects thebase_urlkeyword argument for OpenAI-compatible providers (#1971)from_provider(): RuntimeImportErrorexceptions are no longer masked, making misconfigured installs easier to diagnose (#1975)- Google GenAI:
Uniontypes now allowed in structured output schemas (#1973) - Google GenAI:
thinking_configand additional user-providedGenerationConfigfields now correctly preserved (#1972, #1974) - Cohere: Streaming and V2 API version detection issues resolved (#1983, #1844)
- xAI: Tools-mode validation fixed (#1983)
- Exception handling: Standardized across all providers (#1897)
Changed
- Type checker: Switched from Pyright to
tyfor faster incremental type checking (#1978) - Provider factories:
from_openai,from_anthropic, etc. signatures standardized (#1898)
[1.13.0] - 2025-11-03
Added
- Bedrock: Image input support — converts OpenAI-style image parts to Bedrock's native format
py.typed: Marker file restored for PEP 561 type-checking support (#1868)
Fixed
disable_pydantic_error_url(): Now correctly suppresses Pydantic validation error URLs via monkey-patchingValidationError.__str__()(environment variable approach had no effect post-import)- JSON mode: JSON decode errors now trigger retry logic instead of surfacing as unhandled exceptions (#1856)
- Gemini: Streaming fixed for the Google GenAI SDK (#1864)
- Gemini:
HARM_CATEGORY_JAILBREAKsafety category and Anthropictool_resultcontent blocks now handled correctly (#1867) - Partial: Fields with
default_factoryno longer retain the factory when made optional during streaming - OpenAI: Dependency version constraint updated to support v2 (#1858)
[1.12.0] - 2025-10-27
Fixed
- Python 3.13: Compatibility issues and import path corrections in multimodal processing
- Bedrock: OpenAI-compatible models now correctly parse responses where reasoning appears before text content
- Gemini:
chunk.text ValueErrorwhenfinish_reason=1no longer crashes streaming - Gemini:
thinking_configno longer unintentionally passed to the tools helper - OpenAI:
parse:errorhook now correctly fires forInstructorValidationError - JSON parsing: Broken regex patterns removed from JSON extraction function
- Cohere: V2 API version detection improved (#1844)
[1.11.3] - 2025-09-04
Added
- Hooks: Hook combination via
__add__/combine()— merge multiple hook handlers together - Hooks: Per-call hooks — pass hooks directly to individual
.create()calls without registering globally - Retry:
InstructorRetryExceptionnow tracks all failed attempts including exceptions and raw completions for better introspection - Docs:
llms.txtsupport viamkdocs-llmstxtplugin for AI/LLM consumers
Fixed
InstructorError.__str__(): Now correctly formats failed-attempt details- Retry: Failed attempts propagated through reask handlers
- Imports: Backward compatibility imports restored for
function_callsandvalidatorsmodules
[1.11.1] - 2025-08-27
Changed
- Upgraded all dependencies to latest versions
[1.11.0] - 2025-08-27
Added
- OpenRouter: Provider support in
from_provider()usingOPENROUTER_API_KEY - LiteLLM: Provider support in
from_provider()(#1723) - xAI: Provider utilities following standard provider structure (#1728)
- Batch API: In-memory batching support with improved error handling for OpenAI and Anthropic (#1746)
- Hooks:
completion:errorandcompletion:last_attempthooks now fully implemented (#1729)
Changed
- Codebase reorganized from flat structure to modular provider-based architecture (#1730)
- Provider-specific message conversion logic moved to dedicated handlers (#1724)
Fixed
- Pydantic v2 deprecation warnings resolved by migrating from class
ConfigtoConfigDict(#1782)