Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Create types.ts files with Zod schemas for Output SDK workflows. Use when defining input/output schemas, creating type definitions, or fixing schema-related errors.
.claude/skills/growthxai-output-dev-types-file/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 95% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 51% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 49% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 23% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 285% | 0% |
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.
ALWAYS import z from @outputai/core, NEVER from zod directly:
typescript// CORRECT import { z } from '@outputai/core'; // WRONG - will cause runtime errors import { z } from 'zod';
Related Skill: output-error-zod-import for troubleshooting import issues
typescriptimport { z } from '@outputai/core'; // 1. Workflow Input Schema export const WorkflowInputSchema = z.object( { // Define input fields } ); // 2. Workflow Output Type export type WorkflowInput = z.infer<typeof WorkflowInputSchema>; export type WorkflowOutput = /* output type */; // 3. Step Schemas (for each step) export const StepNameInputSchema = z.object( { // Step input fields } ); export const StepNameOutputSchema = z.object( { // Step output fields } ); // 4. Type Exports export type StepNameInput = z.infer<typeof StepNameInputSchema>; export type StepNameOutput = z.infer<typeof StepNameOutputSchema>;
Schemas passed to 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.
.min(), .max() on z.number() produce minimum/maximum -- rejected by Anthropic..min(), .max(), .length() on z.array() produce minItems/maxItems -- Anthropic only supports minItems of 0 or 1. Values like .length( 3 ) or .min( 2 ) will be rejected..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.
typescript// LLM output schema (sent to provider via Output.object()) -- .describe() ONLY const llmOutputSchema = z.object( { score: z.number().describe( 'Quality score 0-100' ), confidence: z.number().describe( 'Confidence 0-1' ), predictions: z.array( predictionSchema ).describe( 'Exactly 3 predictions' ) } ); // Workflow/step validation schema (Zod-only, NOT sent to LLM) -- .min()/.max()/.length() OK const workflowOutputSchema = z.object( { score: z.number().min( 0 ).max( 100 ).describe( 'Quality score 0-100' ), confidence: z.number().min( 0 ).max( 1 ).describe( 'Confidence 0-1' ), predictions: z.array( predictionSchema ).length( 3 ).describe( 'Exactly 3 predictions' ) } );
| Context | .min()/.max()/.length() | .describe() | |---------|:-:|:-:| | Schema passed to Output.object() | No (numbers or arrays) | Yes | | inputSchema / outputSchema on steps | OK | Optional | | inputSchema / outputSchema on workflows | OK | Optional | | outputSchema on evaluators | OK | Optional |
Define all schemas used in 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.
typescriptimport { z } from '@outputai/core'; // Strings const stringField = z.string(); const optionalString = z.string().optional(); const stringWithDefault = z.string().default( 'default value' ); const describedString = z.string().describe( 'Field description' ); // Numbers const numberField = z.number(); const integerField = z.number().int(); const rangedNumber = z.number().min( 1 ).max( 100 ); // runtime only — NOT safe for Output.object() schemas // Booleans const booleanField = z.boolean(); const defaultBoolean = z.boolean().default( false ); // Enums const enumField = z.enum( [ 'option1', 'option2', 'option3' ] ); const enumWithDefault = z.enum( [ 'small', 'medium', 'large' ] ).default( 'medium' );
typescriptimport { z } from '@outputai/core'; // Arrays const stringArray = z.array( z.string() ); const objectArray = z.array( z.object( { id: z.string(), name: z.string() } ) ); // Objects const nestedObject = z.object( { user: z.object( { id: z.string(), email: z.string().email() } ), settings: z.object( { notifications: z.boolean() } ) } ); // Union Types const flexibleInput = z.union( [ z.string(), z.array( z.string() ) ] ); // Records const keyValueMap = z.record( z.string(), z.number() );
typescriptimport { z } from '@outputai/core'; // String Validations const emailField = z.string().email(); const urlField = z.string().url(); const uuidField = z.string().uuid(); const minLengthString = z.string().min( 1 ); const maxLengthString = z.string().max( 1000 ); // Number Validations const positiveNumber = z.number().positive(); const nonNegativeNumber = z.number().nonnegative(); const percentageNumber = z.number().min( 0 ).max( 100 ); // Array Validations (runtime only — NOT safe for Output.object() schemas) const nonEmptyArray = z.array( z.string() ).min( 1 ); const limitedArray = z.array( z.string() ).max( 10 ); const fixedLengthArray = z.array( z.string() ).length( 3 );
Based on a real workflow (image_infographic_nano):
typescriptimport { z } from '@outputai/core'; // ============================================ // Workflow Schemas // ============================================ export const WorkflowInputSchema = z.object( { content: z.string().describe( 'Text content to generate image ideas from' ), mode: z.enum( [ 'infographic' ] ).default( 'infographic' ).describe( 'Type of image to generate' ), colorPalette: z.string().optional().describe( 'Color palette preference for the images' ), artDirection: z.string().optional().describe( 'Art direction or style preference' ), numberOfIdeas: z.number().min( 1 ).max( 10 ).default( 1 ).describe( 'Number of image concepts to generate' ), referenceImageUrls: z.union( [ z.string(), z.array( z.string() ) ] ).optional().describe( 'Reference image URLs for style guidance (max 14)' ), aspectRatio: z.enum( [ '1:1', '16:9', '9:16', '4:3', '3:4' ] ).default( '1:1' ).describe( 'Aspect ratio for generated images' ), resolution: z.enum( [ '1K', '2K', '4K' ] ).default( '1K' ).describe( 'Resolution for generated images' ), numberOfGenerations: z.number().min( 1 ).max( 10 ).default( 1 ).describe( 'Number of images to generate per concept' ), storageNamespace: z.string().optional().describe( 'S3 folder path for storing images' ) } ); export type WorkflowInput = z.infer<typeof WorkflowInputSchema>; export type WorkflowOutput = string[]; // ============================================ // Step Schemas // ============================================ export const ValidateReferenceImagesInputSchema = z.object( { referenceImageUrls: z.array( z.string() ).optional() } ); export const GenerateImageIdeasInputSchema = z.object( { content: z.string(), numberOfIdeas: z.number(), colorPalette: z.string().optional(), artDirection: z.string().optional() } ); export const GenerateImagesInputSchema = z.object( { input: z.object( { referenceImageUrls: z.union( [ z.string(), z.array( z.string() ) ] ).optional(), aspectRatio: z.enum( [ '1:1', '16:9', '9:16', '4:3', '3:4' ] ), resolution: z.enum( [ '1K', '2K', '4K' ] ), numberOfGenerations: z.number(), storageNamespace: z.string().optional() } ), prompt: z.string() } ); // Schema for LLM response validation export const ImageIdeasSchema = z.object( { ideas: z.array( z.string() ).describe( 'Array of detailed image prompts for Gemini' ) } ); // ============================================ // Type Exports // ============================================ export type ValidateReferenceImagesInput = z.infer<typeof ValidateReferenceImagesInputSchema>; export type GenerateImageIdeasInput = z.infer<typeof GenerateImageIdeasInputSchema>; export type GenerateImagesInput = z.infer<typeof GenerateImagesInputSchema>; export type ImageIdeas = z.infer<typeof ImageIdeasSchema>;
typescript// Good - helps with documentation and error messages z.string().describe( 'User email address for notifications' ) // Avoid - no context for errors z.string()
typescript// Good - workflow works without optional fields numberOfIdeas: z.number().min( 1 ).max( 10 ).default( 1 ) // Avoid - forces users to provide every field numberOfIdeas: z.number().min( 1 ).max( 10 )
typescript// Workflow input schema (what the user provides) export const WorkflowInputSchema = z.object( { ... } ); // Step schemas (internal data shapes) export const StepNameInputSchema = z.object( { ... } );
typescript// Export schema for runtime validation export const UserSchema = z.object( { ... } ); // Export type for TypeScript type checking export type User = z.infer<typeof UserSchema>;
z is imported from @outputai/core.describe() for important fields.optional() or .default().min()/.max() for runtime schemas, .describe() for Output.object() schemas)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| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 9,470 | 7,329 | -23% | 1 | 1 | 0% | 2,339 | 4,564 | +95% | 0 | 0 | — |
case-02 | fail→pass | 15,546 | 8,343 | -46% | 1 | 1 | 0% | 3,144 | 4,743 | +51% | 0 | 0 | — |
case-03 | fail→pass | 13,618 | 7,702 | -43% | 1 | 1 | 0% | 3,125 | 4,668 | +49% | 0 | 0 | — |
case-04 | pass→pass | 16,657 | 8,567 | -49% | 1 | 1 | 0% | 3,156 | 4,419 | +40% | 0 | 0 | — |
case-05 | pass→pass | 11,126 | 6,206 | -44% | 1 | 1 | 0% | 2,303 | 4,225 | +83% | 0 | 0 | — |
case-06 | pass→pass | 8,737 | 7,066 | -19% | 1 | 1 | 0% | 1,856 | 4,237 | +128% | 0 | 0 | — |
case-07 | fail→pass | 14,687 | 6,180 | -58% | 1 | 1 | 0% | 3,335 | 4,088 | +23% | 0 | 0 | — |
case-08 | fail→pass | 4,973 | 3,681 | -26% | 1 | 1 | 0% | 955 | 3,680 | +285% | 0 | 0 | — |
case-09 | pass→pass | 8,706 | 4,135 | -53% | 1 | 1 | 0% | 1,724 | 3,732 | +116% | 0 | 0 | — |
case-10 | pass→pass | 7,302 | 4,370 | -40% | 1 | 1 | 0% | 1,685 | 3,836 | +128% | 0 | 0 | — |
case-11 | fail→pass | 8,660 | 6,369 | -26% | 1 | 1 | 0% | 1,517 | 4,124 | +172% | 0 | 0 | — |
case-12 | fail→pass | 12,626 | 7,693 | -39% | 1 | 1 | 0% | 2,427 | 4,299 | +77% | 0 | 0 | — |
case-13 | fail→pass | 6,917 | 4,958 | -28% | 1 | 1 | 0% | 1,368 | 3,828 | +180% | 0 | 0 | — |
case-14 | fail→pass | 14,960 | 4,268 | -71% | 1 | 1 | 0% | 2,519 | 3,641 | +45% | 0 | 0 | — |
case-15 | pass→pass | 7,201 | 3,105 | -57% | 1 | 1 | 0% | 1,220 | 3,432 | +181% | 0 | 0 | — |
case-16 | pass→pass | 6,348 | 3,910 | -38% | 1 | 1 | 0% | 1,076 | 3,803 | +253% | 0 | 0 | — |
case-17 | pass→pass | 9,969 | 5,172 | -48% | 1 | 1 | 0% | 1,885 | 3,830 | +103% | 0 | 0 | — |
case-18 | pass→pass | 11,187 | 4,542 | -59% | 1 | 1 | 0% | 1,808 | 3,703 | +105% | 0 | 0 | — |
case-19 | pass→pass | 7,371 | 6,083 | -17% | 1 | 1 | 0% | 1,504 | 3,982 | +165% | 0 | 0 | — |
case-20 | fail→pass | 14,912 | 5,070 | -66% | 1 | 1 | 0% | 2,411 | 3,842 | +59% | 0 | 0 | — |
case-21 | pass→pass | 10,202 | 6,085 | -40% | 1 | 1 | 0% | 1,758 | 4,035 | +130% | 0 | 0 | — |
case-22 | pass→pass | 5,149 | 3,096 | -40% | 1 | 1 | 0% | 876 | 3,470 | +296% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +45 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.