ai-sdk — Claude Code rule for structured data
This Claude Code rule covers structured data generation with the Vercel AI SDK. It applies to TypeScript and TSX files.
AGPL-3.0 ★ 1,120 updated 2026-11-16
.cursor/rules/ai-sdk.mdcWhat ai-sdk does
The rule steers Vercel AI SDK code toward generateText with an Output format, replacing the deprecated generateObject pattern. Zod schemas shape objects and arrays; Output.choice() selects from a fixed set, while Output.json() returns JSON without schema validation. Plain text uses Output.text().
For streamed arrays, the rule demonstrates elementStream. Field descriptions with .describe() add context to schema properties, and the error example checks for NoObjectGeneratedError. It also covers structured output alongside tools. The file patterns are **/*.ts and **/*.tsx.
What it helps with
- replace
generateObjectwith the current generation pattern - define object or array output with a Zod schema
- consume array items as streaming completes
- classify text using a fixed set of labels
Example prompts for the agent
- Rewrite this
generateObjectcall usinggenerateText,Output.object(), and a Zod schema. - Show how to stream array items with
elementStream. - Classify this text with
Output.choice()and the options positive, negative, and neutral.
How to install ai-sdk
Manually: put the files in place
.cursor/rules/ai-sdk.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/ai-sdk.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/ai-sdk.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/ai-sdk.mdManually: put the files in place
.clinerules/ai-sdk.mdStep by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules
Questions about ai-sdk
How do I install ai-sdk in Claude Code?
Add the rule file to the project at .claude/rules/ai-sdk.md.
What does ai-sdk do?
It provides Vercel AI SDK patterns for structured objects, arrays, and classification. The guidance also covers streaming and error handling.
Which files does ai-sdk apply to?
It matches TypeScript and TSX files using **/*.ts and **/*.tsx.