instructor_dart 0.6.0
instructor_dart: ^0.6.0 copied to clipboard
Typed, validated structured outputs from LLMs. Build a JSON Schema in plain Dart, with validation and repair retries. Adapters for OpenAI, Anthropic and Gemini.
0.6.0 #
Two pre-1.0.0 decisions, both about what the API promises rather than what it computes. Breaking for anyone who wrote their own adapter; the migration is one word.
-
LlmAdapteris now anabstract base classwith aclose()default, andInstructorhas aclose()that forwards to it. Two problems met here. An adapter constructed without anhttp.Clientcreates one and owns it, and the shape the README leads with passes the adapter inline and never keeps a reference — so nothing could reach that client, and a program following the README sat on an idle socket after its work was done.close()existed only on the three concrete adapters, not on the type callers hold. The second problem is that fixing this by adding a member to anabstract interface classbreaks every third-party implementer, and the roadmap has streaming on it, which would break them a second time. Abaseclass with concrete defaults can grow without breaking anyone, so that is what it is now.To migrate, change
implements LlmAdaptertoextends LlmAdapterand mark your classbase,finalorsealed. Overrideclose()only if your adapter owns something. -
Corrected the integer claim in the README. It said
json['age'] as intis always safe for anintegerfield. It is not, above 2^53:validateaccepts such a value, butnormalizedeliberately leaves it adoublerather than converting lossily, so the cast throws. Measured:1e16,1e17and1e300all validate and all throw onas int. The README now says so and suggests reading such a field asnum, or modelling it as a string.
0.5.0 #
The last things to settle before this can freeze at 1.0.0, all found by re-reviewing the public surface against what a permanent contract would fix.
- Stop
Schema.objectaliasing the caller's map. It stored the exact map passed in, soSchema.object(props)followed byprops['x'] = ...changed the schema afterwards, andschema.propertieswas itself writable, both bypassing every check the factory does and changing whatvalidatedemands. This is the same escape hatch 0.4.0 closed for the constructors, left open in one more place.Schema.objectnow copies into an unmodifiable map, matching whatSchema.enumerationalready documents and does for its list. Breaking only for code that mutated a schema through that aliasing, which was never intended to work. - Make
collectViolationsprivate. It was public with a note that it had to be, "so that schema types can recurse into each other". That was not true:Schemaissealedand every schema type lives in the one library, so the recursion works with it private, and Dart privacy is per-library. Public, it froze an internal accumulator hook, its out-parameter list and its seed-the-path convention, into the 1.0.0 contract.validateis the supported entry point and is unchanged. - Give
SchemaViolationandMessagevalue equality. Both are small immutable value types that callers naturally compare and put in sets: deduplicating the violations acrossExtractionException.attempts, or asserting onLlmRequest.messagesin an adapter test.Messagewas worse than missing equality, it was inconsistent: twoconstidentical messages compared equal through canonicalization while two runtime-built identical ones did not. Both now compare by value. Adding this after 1.0.0 would silently change how existing sets and maps of these types dedup, so it lands now.
0.4.0 #
- Make the concrete schema constructors library-private so the validating
Schema.*factories are the only way to build a schema. Breaking change:StringSchema(...),IntegerSchema(...),NumberSchema(...),BooleanSchema(...),EnumSchema(...),ListSchema(...)andObjectSchema(...)can no longer be called directly; useSchema.string,Schema.integer,Schema.number,Schema.boolean,Schema.enumeration,Schema.listandSchema.objectinstead. The concrete types stay exported for use in return types,switch, and field access, and.optional()still returns the same concrete type. This closes a construction path that skipped the factory checks:Schema.stringrejects an invalid regular expression andSchema.enumerationrejects an empty list and copies its values, and a direct constructor call bypassed both.
0.3.1 #
- Fix
.optional()rejecting an explicit JSONnullon the property it was applied to..optional()only removed the key from the JSON Schemarequiredlist, so a key present with valuenullstill fell through to the leaf schema's type check and failed as a type mismatch instead of being treated as absent. Forced tool calling on OpenAI, Anthropic and Gemini regularly fills in every declared parameter and represents "no value" asnullrather than omitting the key, so this broke.optional()for exactly the case it exists for. A required property givennullis still reported as a violation.
0.3.0 #
- Normalize numeric fields to the Dart type their schema promises instead of
coercing every integral double to
int. Anumberfield given a whole value like42now decodes to adouble(42.0), sojson['price'] as doubleinfromJsonno longer throws after validation reported success; anintegerfield still arrives asint. AddsSchema.normalize, called after validation to do this per node type.
0.2.3 #
- Shorten the screenshot description. pub.dev accepts up to 200 characters but scores only those under 160, so the previous release published cleanly and quietly gave up the documentation points it was meant to earn.
0.2.2 #
- Declare the diagram in
pubspec.yamlso pub.dev renders it on the package page. It was already in the repository and the README, but pub.dev shows only what thescreenshots:field points at.
0.2.1 #
- Shorten the pub.dev description back under the 180-character limit. The previous release grew it past that, which costs the "valid pubspec" points and truncates the text search engines show.
0.2.0 #
- Add
GeminiAdapterfor the Gemini API'sgenerateContent, completing the three major providers. The schema is sent as a function declaration and forced withfunctionCallingConfig.mode: "ANY". Two Gemini-specific shapes are handled:contentsonly accepts theuserandmodelroles, so an assistant message is sent asmodel, and system text goes in the top-levelsystemInstructionrather than being a message. The API key is sent in thex-goog-api-keyheader instead of thekeyquery parameter, so it stays out of URLs and logs.
0.1.2 #
- Docs: tightened the README wording and visuals.
0.1.1 #
- Expand the package description to name what the package does in the words people search for. No code changes.
0.1.0 #
Initial release.
- Plain-Dart schema builder rendering to JSON Schema: objects, strings, integers, numbers, booleans, enums, lists, nesting, optional properties, length/range/pattern constraints.
- Local validation with JSONPath-style violation reporting.
Instructor.extract/extractRawwith an automatic repair loop that feeds validation errors back to the model.OpenAIAdapterfor OpenAI and OpenAI-compatible servers (Ollama, LM Studio, vLLM, OpenRouter), using forced tool calls.AnthropicAdapterfor the Anthropic Messages API, using forced tool use.ExtractionExceptionwith full attempt history.