Skip to main content
Genkit ships with Dotprompt—a file format for defining prompts outside of application code. Prompt files combine YAML frontmatter (model config, input/output schemas) with Handlebars templates. Because prompts live in .prompt files, they can be version-controlled, reviewed, and edited independently of code.

Anatomy of a .prompt file

Save this file as prompts/writeCopy.prompt. Genkit loads all .prompt files from the prompts/ directory (configurable) at startup.

Loading and calling a prompt

Defining prompts in code with definePrompt()

For prompts that are simpler to keep in code, or when you need programmatic control over the message structure, use ai.definePrompt():
You can also pass a function for full control over the message list:

Prompt variants

Variants let you maintain alternate versions of a prompt—for A/B testing, different locales, or model-specific tuning—without duplicating the base file. Create a variant by naming the file <promptName>.<variant>.prompt:
Load a variant by passing the variant option:

Frontmatter reference

The YAML frontmatter supports the following fields:

Picoschema

The input.schema field supports a compact schema syntax called Picoschema:
Append ? to mark a field optional. Use (type, description) for complex types.

Multi-message prompts

To define multiple messages (system + user) in a .prompt file, use {{role}} helpers:

Configuring the prompt directory

Change the directory where Genkit looks for .prompt files:
Set promptDir to null in TypeScript (or omit WithPromptDir in Go) to disable automatic prompt loading entirely.

Rendering a prompt without executing it

Sometimes you want to inspect the final GenerateOptions that a prompt would produce—for debugging or to inject additional parameters before calling the model:

Next steps

Tools

Reference tools by name from inside prompt files.

Models

Learn all available model config options.

Structured Output

Enforce JSON output schemas on prompt responses.

Dev Tools

Test and iterate on prompts in the Dev UI.