Fluent builder for the OpenAI-style json_schema response format map that forces a language model to return output matching a specific structure. A caller obtains an instance from LlmManager.newJsonSchemaResponseFormatBuilder, adds properties created with createProperty and marks the schema strict or lists required fields as needed, then calls build to produce the response_format map that is passed as a modelParameter to LlmManager.invokeInference.
Group: Builders
Methods
strict(boolean strict)
Returns: JsonSchemaResponseFormatBuilder
Sets whether the generated schema enforces strict mode, meaning the model must return output that exactly matches the declared properties with no additional fields. Defaults to true.
| Parameter | Description |
|---|---|
strict | true to require strict adherence to the schema, false to allow deviation |
schemaProperties(Property property)
Returns: JsonSchemaResponseFormatBuilder
Adds a property, created with createProperty, to the top level of the schema being built. Can be called more than once to accumulate several properties.
| Parameter | Description |
|---|---|
property | the property to add to the schema |
schemaRequiredFields(List<String> schemaRequiredFields)
Returns: JsonSchemaResponseFormatBuilder
Sets the names of the top level properties that the model must always include in its response.
| Parameter | Description |
|---|---|
schemaRequiredFields | the property names that are required |
createProperty(String name, String type, String description)
Returns: Property
Creates a new schema property with the given name, JSON type and description. The returned property can be nested inside other properties with addProperty, given items or required fields, and passed to schemaProperties to add it to the schema.
| Parameter | Description |
|---|---|
name | the property name as it will appear in the model's JSON response |
type | the JSON schema type of the property, for example "string", "object" or "array" |
description | text shown to the model describing what value belongs in this property, may be null |
build()
Returns: Map<String,Object>
Assembles the accumulated properties, required fields and strict setting into an OpenAI-compatible response_format map, with type set to json_schema. The returned map is suitable for passing as the response_format model parameter to LlmManager.invokeInference to force the model's reply into this shape.