LangSchema.Converter.OpenAI (LangSchema v0.7.1)
View SourceConverts a LangSchema into a JSON schema compatible with OpenAI's Structured Outputs.
Supported JSON Schema spec
Reference: https://platform.openai.com/docs/guides/structured-outputs/supported-schemas
Supported types
string, number, integer, boolean, object, array, enum, anyOf
Root objects cannot be
anyOftype.
Supported keywords
type,description,enum,constproperties,required,additionalProperties(must befalse)items,anyOf$ref,$defs(recursive schemas supported)
Unsupported keywords
| Type | Unsupported keywords |
|---|---|
| String | minLength, maxLength, pattern, format |
| Number | minimum, maximum, multipleOf |
| Object | patternProperties, unevaluatedProperties, propertyNames, minProperties, maxProperties |
| Array | unevaluatedItems, contains, minContains, maxContains, minItems, maxItems, uniqueItems |
Constraints
- All fields must be
required. additionalPropertiesmust befalseon every object.- Max 100 object properties total, up to 5 levels of nesting.
LangSchema implementation status
| Keyword | Status |
|---|---|
type, description, enum | Supported |
properties, required, additionalProperties | Supported (auto-enforced) |
items | Supported |
anyOf | Supported |
nullable | Supported (via ["type", "null"]) |
const | Not yet implemented |
$ref, $defs | Not yet implemented |
Summary
Functions
Wraps the given JSON schema into the structured output envelope expected by OpenAI's Chat API (response_format: "json_schema").
Functions
Wraps the given JSON schema into the structured output envelope expected by OpenAI's Chat API (response_format: "json_schema").
This implementation follows the specification described under: OpenAI API Reference - Create Chat Completion (Request body → response_format → JSON schema → json_schema).
It sets the name, attaches the provided JSON schema under the schema field, and enforces strict: true.
If a description is provided in the options, it will be added as well.