Creating types.ts Files with Zod Schemas
Overview
This skill documents how to create types.ts files for Output SDK workflows. These files contain Zod schemas for input/output validation and their corresponding TypeScript types.
When to Use This Skill
- Creating a new workflow's type definitions
- Adding new schemas for steps
- Fixing schema validation errors
- Refactoring existing type definitions
Critical Import Rule
ALWAYS import z from @outputai/core, NEVER from zod directly:
Related Skill: output-error-zod-import for troubleshooting import issues
Basic Structure
CRITICAL: Schema Constraints for LLM Output
Schemas passed to aiSdk.Output.object() are sent to LLM providers as tool definitions. Anthropic rejects several JSON Schema constraints that Zod methods produce. Getting this wrong causes runtime errors.
What Is NOT Allowed in LLM Output Schemas
- Numbers:
.min(),.max()onz.number()produceminimum/maximum-- rejected by Anthropic. - Arrays:
.min(),.max(),.length()onz.array()produceminItems/maxItems-- Anthropic only supportsminItemsof0or1. Values like.length( 3 )or.min( 2 )will be rejected.
Use .describe() Instead
.describe() is the primary mechanism for guiding LLM output quality. LLM providers use field names and descriptions from the schema to understand what each field should contain. Write clear, specific descriptions that communicate your intent.
Important: .describe() replaces both unsupported constraints AND prompt-based format instructions. Do not also describe the schema in the prompt -- the schema is sent to the provider automatically, and duplicating it reduces performance and creates drift risk. See output-dev-prompt-file for details.
When to Use Which
LLM Schemas Must Live in types.ts
Define all schemas used in aiSdk.Output.object() in types.ts and import them in step functions. Never define them inline -- this causes duplication and makes it harder to verify they follow the constraints above.
Common Schema Patterns
Basic Types
Complex Types
Validation Patterns
Complete Example
Based on a real workflow (image_infographic_nano):
Best Practices
1. Use Descriptive Field Descriptions
2. Provide Sensible Defaults
3. Separate Workflow and Step Schemas
4. Export Both Schemas and Types
Verification Checklist
-
zis imported from@outputai/core - WorkflowInputSchema is defined and exported
- WorkflowInput type is exported
- WorkflowOutput type is defined
- Each step has corresponding input/output schemas
- All schemas have
.describe()for important fields - Optional fields use
.optional()or.default() - Numeric fields have appropriate constraints (
.min()/.max()for runtime schemas,.describe()foraiSdk.Output.object()schemas) - Code follows style conventions (see output-dev-code-style)
Related Skills
output-dev-workflow-function- Using schemas in workflow definitionsoutput-dev-step-function- Using schemas in step definitionsoutput-dev-evaluator-function- Using schemas in evaluator definitionsoutput-dev-folder-structure- Where types.ts belongs in the projectoutput-error-zod-import- Troubleshooting schema import issuesoutput-dev-code-style- Code style conventions


