.prompt files, they can be version-controlled, reviewed, and edited independently of code.
Anatomy of a .prompt file
prompts/writeCopy.prompt. Genkit loads all .prompt files from the prompts/ directory (configurable) at startup.
Loading and calling a prompt
- TypeScript
- Go
- Python
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():
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:
variant option:
Frontmatter reference
The YAML frontmatter supports the following fields:Picoschema
Theinput.schema field supports a compact schema syntax called Picoschema:
? 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:
- TypeScript
- Go
- Python
Rendering a prompt without executing it
Sometimes you want to inspect the finalGenerateOptions 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.
