WorkersGenerators
Schema
📸 Screenshots
Here are visual examples of this section:
Schema - Worker Configuration Interface
1. Overview and Purpose
The Schema worker extracts structured data from unstructured text input using AI-powered data extraction. It dynamically creates a schema based on user-defined output handles and uses OpenAI's language models to parse the input text and populate the schema fields. This worker is particularly useful for converting natural language descriptions into structured JSON data.
2. Configuration Parameters
model: The OpenAI model to use for data extraction (defaults to "gpt-4o")
3. Input/Output Handles
input: Input handle - accepts string text to be parsed and structuredjson: Output handle - returns JSON object containing all extracted field values- Dynamic output handles: Additional output handles are created based on user configuration, supporting types like boolean, number, string, arrays, and enums
4. Usage Examples with Code
// Schema worker extracting contact information
const schemaWorker = agent.createWorker("schema", {
model: "gpt-4o"
});
// Input: "John Doe is 30 years old and works as a software engineer"
// With schema fields: name (string), age (number), occupation (string)
// Output JSON: { name: "John Doe", age: 30, occupation: "software engineer" }5. Integration Examples
The Schema worker fits well at the beginning of data processing pipelines, converting unstructured text into structured data that can be consumed by other workers. It's commonly used after text extraction workers and before data validation or storage workers.
6. Best Practices
- Define clear, descriptive prompts for each schema field to improve extraction accuracy
- Use appropriate data types (string, number, boolean, arrays, enums) that match your expected output
- Test with sample inputs to ensure the schema captures all necessary information
- Consider using enums for fields with limited possible values to improve consistency
7. Troubleshooting Tips
- If extraction fails, check that your input text contains the information needed for the schema fields
- Verify your OpenAI API key is valid and has sufficient credits
- For complex schemas, break them down into smaller, more focused extraction tasks
- Review the JSON output to ensure all expected fields are being populated correctly
