WorkersGenerators
Structuredoutput
📸 Screenshots
Here are visual examples of this section:
Structuredoutput - Worker Configuration Interface
1. Overview and Purpose
The Structured Output worker extracts structured data from input text and chat history according to a user-defined schema. It uses AI to parse unstructured content and return formatted data in specified fields. The worker supports various data types including strings, numbers, booleans, arrays, and enums, making it ideal for data extraction and content parsing tasks.
2. Configuration Parameters
model: The AI model to use for structured data extraction (defaults to "openai/gpt-4o")instructions: Custom instructions for data extraction (defaults to extracting data according to schema, using null for missing fields)
3. Input/Output Handles
input: Input handle - accepts string text to extract data fromhistory: Input handle - accepts chat history for additional contextJSON: Output handle - returns extracted data as JSON object- Dynamic output handles are created based on user-defined schema fields
4. Usage Examples with Code
// Configure the worker with custom schema fields
const structuredWorker = {
parameters: {
model: "openai/gpt-4o",
instructions: "Extract contact information from the input text"
},
fields: {
input: "John Doe, email: john@example.com, phone: 555-0123",
history: [], // Optional chat context
}
}
// The worker will extract data based on your defined schema fields
// Output might include: { name: "John Doe", email: "john@example.com", phone: "555-0123" }5. Integration Examples
This worker is commonly used in data processing pipelines to convert unstructured text into structured formats. It pairs well with chat workers for conversational data extraction and with database workers for storing extracted information.
6. Best Practices
- Define clear, descriptive field names and prompts for better extraction accuracy
- Use appropriate data types (string, number, boolean, arrays, enums) for your schema fields
- Provide clear instructions that specify what data to extract and how to handle missing information
- Test with sample data to ensure the schema captures all required information
7. Troubleshooting Tips
- If extraction is inaccurate, refine your instructions to be more specific about the expected data format
- Ensure input text contains the data you're trying to extract - the worker returns null for missing fields
- Check that your schema field types match the expected data format (e.g., use number type for numeric data)
- For complex extractions, consider breaking them into multiple simpler schema fields
