Prompt Engineering in Vercel's AI SDK

Just a guy who loves to write code and watch anime.
Search for a command to run...

Just a guy who loves to write code and watch anime.
No comments yet. Be the first to comment.
Qualities that make outstanding builders.

Bipedal vs quadrupedal: how many legs This is about the number of legs the creature walks on. Bipedal. Two legs. Humans, ostriches, T-rex, kangaroos, most fantasy humanoids. Quadrupedal. Four legs. Do

Intro You hear "lerp" and "smoothstep" everywhere in game dev. They sound like math jargon. They're not. Both are small tools that do the same job: smoothly move from one value to another. The problem

What is Kinematics Kinematics is the math field. It's the study of how things move without worrying about forces (which would be dynamics). FK and IK are the two branches: forward kinematics and inver

Intro Textures are usually the biggest cost in a 3D scene. Memory, bandwidth, and load time all get eaten by them. Resizing them is the obvious lever. There's more. This post is about the less obvious

Choose appropriate models -> More powerful models like GPT-4 handle tools much better than smaller models
Keep tool sets manageable -> Limit yourself to 5 or fewer tools when possible
Simplify parameter structures -> Complex nested schemas with many optional fields confuse models
Use meaningful naming -> Clear, descriptive names for tools and parameters help models understand their purpose
Add descriptions to parameters -> Use Zod's .describe() method to clarify what each parameter does:
parameters: z.object({
location: z.string().describe("City and state or country name"),
includeHourly: z
.boolean()
.describe("Whether to include hour-by-hour forecast"),
});
Document tool outputs -> Explain what your tool returns in its description, especially when there are dependencies between tools
Provide examples -> Including sample tool calls and results in your prompt can guide the model:
Example tool call:
weather({"location": "New York, NY"})
Example result:
{"temperature": 72, "conditions": "Partly cloudy"}
The translation between Zod schemas and what models actually produce isn't always perfect, especially with specific data types.
Models return dates as strings, but Zod typically expects JavaScript Date objects. The solution is to use transformers:
const schema = z.object({
events: z.array(
z.object({
event: z.string(),
date: z
.string()
.date()
.transform((value) => new Date(value)),
})
),
});
This validates the date string format first, then converts it to a proper Date object.
The AI SDK offers two helpful debugging techniques:
To check if your configuration is supported:
const result = await generateText({
model: openai("gpt-4o"),
prompt: "Hello, world!",
});
console.log(result.warnings);
This helps identify when you're using features not supported by a particular provider.
For deeper debugging, you can see exactly what's being sent to the provider:
const result = await generateText({
model: openai("gpt-4o"),
prompt: "Hello, world!",
});
console.log(result.request.body);
This shows you the raw HTTP request body, letting you verify the exact payload being sent to the model.