Generate structured outputIntroduced in 2026.02
The function ai.text.structuredCompletion can be used to generate structured output based on a textual input prompt and an output schema, represented as a Cypher map.
It is similar to submitting a prompt to an LLM, but with the additional guarantee that the output conforms to the requested schema.
Syntax |
|
||
Description |
Generate structured output as a map based on the specified prompt and JSON schema. |
||
Inputs |
Name |
Type |
Description |
|
|
The prompt to generate output from. |
|
|
|
A map describing the JSON schema for the desired output. |
|
|
|
The identifier of the provider: 'Azure-OpenAI', 'Bedrock', 'OpenAI', 'VertexAI'. |
|
|
|
Provider specific configuration, use |
|
Returns |
|
A structured map conforming to the provided schema. |
|
Examples
This example provides the model with a list of movie titles and plots, alongside a few movie genres, and asks to sort the movies into genres.
WITH
{
type: 'object',
properties: {
recipes: {
type: 'array',
maxItems: 5,
minItems: 5,
items: {
type: 'object',
properties: {
name: {type: "string"},
description: {type: "string"},
tastiness: {type: "integer", minimum: 1, maximum: 5}
},
required: ["name", "description", "tastiness"],
additionalProperties: false
}
}
},
required: ['recipes'],
additionalProperties: false
} AS schema,
{
token: $openaiToken,
model: 'gpt-5-nano'
} AS conf
RETURN
ai.text.structuredCompletion(
'Classify these films into their correct genres, using only the genres ['SciFi’, 'Horror’, 'Action’, 'Romance’, 'Drama’, 'Documentary’, 'Other’]. Films: ' + movies,
schema,
'openai',
conf
) AS result
WITH
{
type: 'object',
properties: {
recipes: {
type: 'array',
maxItems: 5,
minItems: 5,
items: {
type: 'object',
properties: {
name: {type: "string"},
description: {type: "string"},
tastiness: {type: "integer", minimum: 1, maximum: 5}
},
required: ["name", "description", "tastiness"],
additionalProperties: false
}
}
},
required: ['recipes'],
additionalProperties: false
} AS schema,
{
token: $azureopenaiToken,
resource: $azureopenaiResource,
model: 'gpt-5-mini'
} AS conf
RETURN
ai.text.structuredCompletion(
'Classify these films into their correct genres, using only the genres ['SciFi’, 'Horror’, 'Action’, 'Romance’, 'Drama’, 'Documentary’, 'Other’]. Films: ' + movies,
schema,
'azure-openai',
conf
) AS result
WITH
{
type: 'object',
properties: {
recipes: {
type: 'array',
maxItems: 5,
minItems: 5,
items: {
type: 'object',
properties: {
name: {type: "string"},
description: {type: "string"},
tastiness: {type: "integer", minimum: 1, maximum: 5}
},
required: ["name", "description", "tastiness"],
additionalProperties: false
}
}
},
required: ['recipes'],
additionalProperties: false
} AS schema,
{
apiKey: $vertexaiToken,
project: $vertexaiProject,
region: $vertexaiRegion,
model: 'gemini-2.5-flash-lite',
publisher: 'google'
} AS conf
RETURN
ai.text.structuredCompletion(
'Classify these films into their correct genres, using only the genres ['SciFi’, 'Horror’, 'Action’, 'Romance’, 'Drama’, 'Documentary’, 'Other’]. Films: ' + movies,
schema,
'vertexai',
conf
) AS result
WITH
{
type: 'object',
properties: {
recipes: {
type: 'array',
maxItems: 5,
minItems: 5,
items: {
type: 'object',
properties: {
name: {type: "string"},
description: {type: "string"},
tastiness: {type: "integer", minimum: 1, maximum: 5}
},
required: ["name", "description", "tastiness"],
additionalProperties: false
}
}
},
required: ['recipes'],
additionalProperties: false
} AS schema,
{
accessKeyId: $bedrockKey,
secretAccessKey: $bedrockSecret,
region: 'us-east-1',
model: 'amazon.nova-micro-v1:0'
} AS conf
RETURN
ai.text.structuredCompletion(
'Classify these films into their correct genres, using only the genres ['SciFi’, 'Horror’, 'Action’, 'Romance’, 'Drama’, 'Documentary’, 'Other’]. Films: ' + movies,
'bedrock',
conf
) AS result
| result |
|---|
|
This example asks the model to classify reviews (either positive, negative, or neutral) and to provide a reson for its judgement.
WITH [
"Extremely well-prepared and tasty lunch with stylish presentations. The salad buffet is well-stocked with various fine pasta salads, potato salads, etc.
The staff is friendly and the service is impeccable.",
"The lunch menu looked nice and the food looked good when it arrived but unfortunately was completely tasteless. Can't give anything but a one when I factor in the expensive price point."
] AS reviewsList
WITH
reduce(acc = '[', r IN reviewsList | acc + '"' + r + '"' + ', ') + ']' AS reviews,
{token: $openaiToken, model: 'gpt-5-nano'} AS conf,
{
type: 'object',
properties: {
sentiments: {
type: 'array',
items: {
type: 'object',
properties: {
sentiment: {type: "string", enum: ['positive', 'negative', 'neutral']},
reason: {type: "string"}
},
required: ["sentiment", "reason"],
additionalProperties: false
}
}
},
required: ['sentiments'],
additionalProperties: false
} AS schema,
{
token: $openaiToken,
model: 'gpt-5-nano'
} AS conf
RETURN
ai.text.structuredCompletion(
'Classify these films into their correct genres, using only the genres ['SciFi’, 'Horror’, 'Action’, 'Romance’, 'Drama’, 'Documentary’, 'Other’]. Films: ' + movies,
schema,
'openai',
conf
) AS result
WITH [
"Extremely well-prepared and tasty lunch with stylish presentations. The salad buffet is well-stocked with various fine pasta salads, potato salads, etc.
The staff is friendly and the service is impeccable.",
"The lunch menu looked nice and the food looked good when it arrived but unfortunately was completely tasteless. Can't give anything but a one when I factor in the expensive price point."
] AS reviewsList
WITH
reduce(acc = '[', r IN reviewsList | acc + '"' + r + '"' + ', ') + ']' AS reviews,
{token: $openaiToken, model: 'gpt-5-nano'} AS conf,
{
type: 'object',
properties: {
sentiments: {
type: 'array',
items: {
type: 'object',
properties: {
sentiment: {type: "string", enum: ['positive', 'negative', 'neutral']},
reason: {type: "string"}
},
required: ["sentiment", "reason"],
additionalProperties: false
}
}
},
required: ['sentiments'],
additionalProperties: false
} AS schema,
{
token: $azureopenaiToken,
resource: $azureopenaiResource,
model: 'gpt-5-mini'
} AS conf
RETURN
ai.text.structuredCompletion(
'Classify these films into their correct genres, using only the genres ['SciFi’, 'Horror’, 'Action’, 'Romance’, 'Drama’, 'Documentary’, 'Other’]. Films: ' + movies,
schema,
'azure-openai',
conf
) AS result
WITH [
"Extremely well-prepared and tasty lunch with stylish presentations. The salad buffet is well-stocked with various fine pasta salads, potato salads, etc.
The staff is friendly and the service is impeccable.",
"The lunch menu looked nice and the food looked good when it arrived but unfortunately was completely tasteless. Can't give anything but a one when I factor in the expensive price point."
] AS reviewsList
WITH
reduce(acc = '[', r IN reviewsList | acc + '"' + r + '"' + ', ') + ']' AS reviews,
{token: $openaiToken, model: 'gpt-5-nano'} AS conf,
{
type: 'object',
properties: {
sentiments: {
type: 'array',
items: {
type: 'object',
properties: {
sentiment: {type: "string", enum: ['positive', 'negative', 'neutral']},
reason: {type: "string"}
},
required: ["sentiment", "reason"],
additionalProperties: false
}
}
},
required: ['sentiments'],
additionalProperties: false
} AS schema,
{
apiKey: $vertexaiToken,
project: $vertexaiProject,
region: $vertexaiRegion,
model: 'gemini-2.5-flash-lite',
publisher: 'google'
} AS conf
RETURN
ai.text.structuredCompletion(
'Classify these films into their correct genres, using only the genres ['SciFi’, 'Horror’, 'Action’, 'Romance’, 'Drama’, 'Documentary’, 'Other’]. Films: ' + movies,
schema,
'vertexai',
conf
) AS result
WITH [
"Extremely well-prepared and tasty lunch with stylish presentations. The salad buffet is well-stocked with various fine pasta salads, potato salads, etc.
The staff is friendly and the service is impeccable.",
"The lunch menu looked nice and the food looked good when it arrived but unfortunately was completely tasteless. Can't give anything but a one when I factor in the expensive price point."
] AS reviewsList
WITH
reduce(acc = '[', r IN reviewsList | acc + '"' + r + '"' + ', ') + ']' AS reviews,
{token: $openaiToken, model: 'gpt-5-nano'} AS conf,
{
type: 'object',
properties: {
sentiments: {
type: 'array',
items: {
type: 'object',
properties: {
sentiment: {type: "string", enum: ['positive', 'negative', 'neutral']},
reason: {type: "string"}
},
required: ["sentiment", "reason"],
additionalProperties: false
}
}
},
required: ['sentiments'],
additionalProperties: false
} AS schema,
{
accessKeyId: $bedrockKey,
secretAccessKey: $bedrockSecret,
region: 'us-east-1',
model: 'amazon.nova-micro-v1:0'
} AS conf
RETURN
ai.text.structuredCompletion(
'Classify these films into their correct genres, using only the genres ['SciFi’, 'Horror’, 'Action’, 'Romance’, 'Drama’, 'Documentary’, 'Other’]. Films: ' + movies,
'bedrock',
conf
) AS result
| result |
|---|
|
Schema requirements
The schema argument is a Cypher map that must adhere to the JSON schema specifications of the chosen provider.
Although most providers support standard JSON schema types (string, number, boolean, object, array), there are important differences in strictness and supported keywords.
| Provider | Schema guidelines |
|---|---|
OpenAI / Azure-OpenAI |
Uses a strict subset of JSON Schema. See the OpenAI docs for more info.
|
Vertex AI |
Uses a subset of the OpenAPI 3.0 Schema Object. See the VertexAI docs for more info.
|
Bedrock |
Uses the Converse API’s tool definition format.
|
|
If you provide a schema with unsupported keywords for a specific provider, the function will return an error from the provider’s API. Always start with a simple schema and increase complexity incrementally. |
Providers
You can generate structured output via the following providers:
-
OpenAI (
openai) -
Azure OpenAI (
azure-openai) -
Google Vertex AI (
vertexai) -
Amazon Bedrock Models (
bedrock)
OpenAI
| Name | Type | Default | Description |
|---|---|---|---|
|
|
- |
Model ID (see OpenAI → Models). |
|
|
- |
OpenAI API key (see OpenAI → API Keys). |
|
|
|
Optional vendor options that will be passed on as-is in the request to OpenAI (see OpenAI → Create a model response). |
You can change OpenAI’s base URL (default: https://api.openai.com) via the genai.openai.baseurl setting.
The change applies to all ai.text.* calls that use OpenAI.
See Configuration settings → genai.openai.baseurl.
|
Azure OpenAI
| Name | Type | Default | Description |
|---|---|---|---|
|
|
- |
Model ID (see Azure → Azure OpenAI in Foundry Models). |
|
|
- |
Azure resource name. |
|
|
- |
Azure OAuth2 bearer token. |
|
|
|
Optional vendor options that will be passed on as-is in the request to Azure. |
Google VertexAI
| Name | Type | Default | Description |
|---|---|---|---|
|
|
- |
Model resource name (see Vertex AI → Model Garden). |
|
|
- |
Google cloud project ID. |
|
|
- |
Google cloud region (see Vertex AI → Locations). |
|
|
'google' |
Model publisher. |
|
|
- |
Vertex AI API key. |
|
|
- |
Vertex API access token. |
|
|
|
Optional vendor options that will be passed on as-is in the request to VertexAI (see Vertex AI → Method: models.generateContent). |
Exactly one of apiKey or token must be provided.
|
Amazon Bedrock Models
This provider supports most Bedrock models and follows the Converse API.
| Name | Type | Default | Description |
|---|---|---|---|
|
|
- |
Model ID or its ARN. |
|
|
- |
Amazon region (see Amazon Bedrock → Model Support). |
|
|
- |
Amazon access key ID. |
|
|
- |
Amazon secret access key. |
|
|
|
Optional vendor options that will be passed on as-is in the request to Bedrock (see Amazon Bedrock → Inference request parameters and response fields). |