Skip to main content

Overview

By default, AI agents return natural language responses in markdown format. To get structured data, use the outputType parameter to specify the desired format. Output Types: When using structured_json or structured_csv, WebRun validates the output against your schema before returning it.

Output Type: text

The default output type returns natural language responses formatted as markdown. No outputSchema is required.

Request Example

Response

The response contains markdown-formatted text:

Output Type: structured_json

Use structured_json to get validated JSON output. The outputSchema parameter accepts a standard JSON Schema object that defines the expected response structure.

Supported JSON Schema Types

  • string - Text values
  • number - Numeric values (integers and decimals)
  • boolean - True/false values
  • object - Nested objects with defined properties
  • array - Arrays with defined item structure

Request Example

Response

The response is guaranteed to match your schema:
When using outputType: "structured_json", the response is guaranteed to match your schema. The data.message field contains a valid JSON string that can be directly parsed.

Output Type: structured_csv

Use structured_csv to get CSV formatted output. The outputSchema parameter accepts an array of column names that define the CSV structure.

Request Example

Response

The response contains CSV formatted data with the specified columns:

Parsing CSV Response

When using outputType: "structured_csv", the outputSchema must be an array of column name strings. The first row of the output will be the header row containing these column names.

Webhook Integration

Combine structured output with webhooks to automatically deliver validated data to your systems when tasks complete.
Use submittedData: "ai_response" to receive only the AI’s output (text, structured_json, or structured_csv). See the Webhooks guide for complete documentation.

Legacy Approach (Deprecated)

The approach of embedding schema descriptions in prompt is deprecated. Use the native outputType and outputSchema parameters instead for guaranteed validation and consistent output.
The examples below show the legacy pattern for reference. New implementations should use the Native JSON Schema Support documented above.

JSON Output Pattern (Legacy)

The most common pattern for structured output is requesting JSON in your task description.

Basic Example

Expected Response:

Parsing the Result


Array Results

Request arrays for lists of items.

Complex Nested Structures

Request nested JSON for complex data.

Example: E-commerce Product Details


Validation with Zod (TypeScript)

Use Zod for runtime validation and type safety.

Install Zod

Define Schema

Validate Response


Handling Parse Errors

Sometimes the AI returns malformed JSON. Implement fallback strategies:

Strategy 1: Extract JSON from Text

Strategy 2: Request Re-formatting


Best Practices

1. Be Specific in Schema Description

2. Request Array Length Limits

Prevent unexpectedly large responses:

3. Specify Data Types Clearly

4. Handle Missing Data

Specify how to handle missing fields:

5. Use TypeScript for Type Safety


Complete Example: Product Comparison


CSV Output

For tabular data, CSV can be simpler than JSON: