Only in Mage Pro.Try our fully managed solution to access this advanced feature.
1. What is an AI Block?
An AI block is a special type of block in a Mage pipeline that uses a Large Language Model (LLM) to:- Generate text or code
- Return structured data in a defined schema
- Trigger other pipelines as tools
- Validate outputs before passing them downstream
- Write and validate executable code
- Produce structured outputs for downstream blocks
- Decide which other pipelines to trigger and pass them variables
2. How to Use an AI Block
- Add a new block in your Mage pipeline and set its type to
ai
. - Write a prompt — the main instruction for the AI.
- Optionally define output settings:
- Code generation (
output.code
) - Structured JSON schema (
output.format
)
- Code generation (
- (Optional) Configure tools to allow the AI to trigger other pipelines.
- Run the pipeline — Mage will send your prompt and configuration to the AI model, validate the output (if specified), and pass it to the next blocks.
3. AI Block Configuration
3.1 Basic Structure
3.2 Fields
prompt (Required)
The instruction to send to the AI model.- Supports multi-line strings with
|
. - Example:
output
Controls how the AI’s response is validated and structured.- Code Output
- Structured Format Output
- Unstructured Output
tools
Lets the AI trigger other pipelines as part of execution.4. JSON Schema Support for Structured Outputs
Theoutput.format
and variables
fields use JSON Schema draft-07 (subset) to define:
type
— string, number, integer, boolean, array, objectdescription
— field descriptionenum
— allowed valuesitems
— item schema for arraysminItems
,maxItems
— constraints for arrayspattern
— regex validation for stringsrequired
— list of required keysoneOf
,anyOf
,allOf
— branching validation$ref
,$defs
— recursive or modular schemas
5. Best Practices
- Use
output.code
only when expecting executable code. - Use
output.format
for predictable structured outputs. - Avoid defining both
code
andformat
in the same block. - Use multi-line prompts with
|
for readability. - Only include fields you need — minimal configs run faster.
- Always include a
validation
prompt for critical outputs. - When chaining pipelines, define
variables
clearly for tool execution.