14 KiB
14 KiB
Changelog
All notable changes to instructor are documented here.
Format: Keep a Changelog Versioning: Semantic Versioning
[Unreleased]
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)
[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)