Skip to content
Back to skills

Llm Output Schema Constraints

ASecurity

Zod schema constraints that Anthropic rejects or silently ignores when sent as structured-output tool definitions via aiSdk.Output.object(). Use when writing or reviewing Zod schemas passed to aiSdk.Output.object(), or debugging structured-output validation errors.

  • 440 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 1, 2026
ai-agentstypescriptdebugging

Security analysis

A100/100

Scanned September 1, 2026

npx -y skills add growthxai/output --skill llm-output-schema-constraints --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Llm Output Schema Constraints?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Llm Output Schema Constraints
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/growthxai-llm-output-schema-constraints/badge)](https://www.skillsdirectory.com/skills/growthxai-llm-output-schema-constraints)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: llm-output-schema-constraints
description: Zod schema constraints that Anthropic rejects or silently ignores when sent as structured-output tool definitions via aiSdk.Output.object(). Use when writing or reviewing Zod schemas passed to aiSdk.Output.object(), or debugging structured-output validation errors.
---

## Schema Constraints for LLM Structured Output

When using `aiSdk.Output.object()` with `generateText`, the Zod schema is converted to JSON Schema and sent to the LLM provider as a tool definition. **Anthropic does not support many JSON Schema constraints**, which means certain Zod methods will cause errors or be silently ignored when the schema is sent to the provider.

### Unsupported constraints in LLM output schemas

**Numbers**: `.min()`, `.max()` on `z.number()` produce `minimum`/`maximum` — rejected by Anthropic.

**Arrays**: `.min()`, `.max()`, `.length()` on `z.array()` produce `minItems`/`maxItems` — Anthropic only supports `minItems` of `0` or `1`. Any other value (e.g. `.length(3)`, `.min(2)`) will be rejected.

### Rule: Use `.describe()` instead of numeric/array constraints for LLM output schemas

```typescript
import { aiSdk } from '@outputai/llm';

// LLM output schema - sent to provider via aiSdk.Output.object()
output: aiSdk.Output.object( {
  schema: z.object( {
    score: z.number().describe( 'Quality score 0-100' ),
    predictions: z.array( predictionSchema ).describe( 'Exactly 3 predictions' )
  } )
} )
```

```typescript
// Workflow/evaluator validation schema - Zod-only, NOT sent to LLM
export const workflowOutputSchema = z.object( {
  score: z.number().min( 0 ).max( 100 ).describe( 'Quality score 0-100' ),
  predictions: z.array( predictionSchema ).length( 3 ).describe( 'Exactly 3 predictions' )
} );
```

### When to use which

| Context | `.min()/.max()/.length()` | `.describe()` |
|---------|:-:|:-:|
| Schema passed to `aiSdk.Output.object()` | No (numbers or arrays) | Yes |
| `inputSchema` / `outputSchema` on workflows | OK | Optional |
| `outputSchema` on evaluators | OK | Optional |
| `workflowOutputSchema` in types.ts | OK | Optional |

The `.describe()` annotation guides the LLM on expected ranges and counts. The `.min()/.max()/.length()` constraints are for runtime Zod validation only and should be used on schemas that validate data within your application, not schemas sent to LLM providers.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.