Join our newsletter to stay up to date on our progress!
Join our newsletter to stay up to date on our progress!
Our Inversion structured language models support fast, reliable, typed JSON Schema generation. This allows you to supply a JSON Schema to constrain the output of your completions, in order to ensure the data is valid and safe to use in your application.
Inversion has the fastest structured generation anywhere.
We also deeply support Zod, Pydantic, and regular expressions. It is highly recommended that you use Zod or Pydantic for your schemas instead of writing raw JSON Schema - it is easier to read and write, grants you runtime validation and type safety, autocomplete, and more.
You can use an Inversion model to extract the exact type of structured data you need for your application reliably every single time, with deep control:
ai.completions.create({
prompt: "i am paul atreides i'm 19",
schema: z.object({
name: z.string().regex(/[A-Z_]+/),
age: z.number().int()
})
})
// Output:
{ name: "PAUL_ATREIDES", age: 19 }
See below for details about each major feature. We support all of the following JSON schema features and more: strings (enums, min/max, email, datetime, url, uuid/ulid/cuid/etc, custom regex, literals, ipv4/v6, etc), numbers (float, integer, scientific, positive, hexadecimal, etc), booleans, null, objects (optional and required properties, nested objects and arrays, records, etc), arrays (min/max length, nested objects and arrays, union child types, tuples, etc), arbitrary JSON (any/unknown, endless recursion, etc), dates/times, string templates, and more.
z.string()
"hello!"
Any valid JSON string, in any language.
{ "type": "string" }
z.number()
-3.142e+10
Any valid JSON number - supports floating points, integers, and scientific notation.
{ "type": "number" }
z.number().int()
420
Any integer, could be positive or negative.
{ "type": "integer" }
z.boolean()
true
{ "type": "boolean" }
z.null()
null
{ "type": "null" }
z.array(...)
[7, 8, 9]
Any valid JSON array, with a given item type. Supports min/max length, nested objects and arrays, union child types, tuples (fixed length arrays with positional child types), and more.
{ "type": "array" }
z.object({...})
{ age: 42 }
Any valid JSON object. You can supply required and optional properties, nested objects, or an arbitrary object with z.record(z.any())
.
{ "type": "object" }
z.enum([...])
"red" | "blue"
One of a list of possible literal values (strings, numbers, etc). Very useful for extraction, classification, and picking from a set of values in function calling.
{ "enum": ... }
z.union([...])
"hi" | 5
One of a list of possible types. Very useful if you want to allow multiple types for a single field, and can be used with discriminated unions to quickly parse the result in your application.
{ "anyOf": ... }
z.string().email()
"paul@example.com"
{ "format": "email" }
z.string().url()
"y.x.com/z?page=0"
{ "format": "uri" }
z.coerce.date()
"2024-03-15T12:00:00Z"
A valid date-time string. Can be auto-parsed as a Date
with Zod coercion. Variable precision fractional seconds, timezone, and alternate formats available.
{ "format": "date-time" }
z.string().regex(...)
/[a-z]+/
Any valid string that matches against a supplied custom regular expression.
{ "pattern": ... }
z.tuple([...])
["hi", 5]
A fixed-length array with positional child types. Very useful for fixed-shape structure, like 2D point or other vector coordinates.
{ "items": ... }
z.string().ip({version:'v4'})
"127.0.0.1"
{ "format": "ipv4" }
z.string().ip({version:'v6'})
"::ffff:7f00:1"
{ "format": "ipv6" }