Skip to main content
Genkit provides powerful tools for managing prompts as code. Define prompts with variables, system instructions, model configuration, and output schemas - all in a single reusable unit.

What are Prompts?

A prompt in Genkit is a reusable template that encapsulates:
  • Prompt text with variable placeholders
  • System instructions
  • Model selection and configuration
  • Input and output schemas
  • Tools and tool choice settings
  • Few-shot examples
Prompts can be defined programmatically or stored in .prompt files (dotprompt format).

Defining Prompts Programmatically

Dotprompt Files

For better organization, store prompts in .prompt files using the dotprompt format:

Basic Dotprompt File

Save this as prompts/recipe.prompt.

Loading Dotprompt Files

Handlebars Syntax

Dotprompt uses Handlebars templating:

Variables

Conditionals

Loops

Built-in Helpers

Prompt Variants

Create multiple variants of a prompt for A/B testing:

System Instructions

Define system-level instructions separately from the user prompt:
Or in the frontmatter:

Multi-turn Conversations

Prompts can include conversation history:

Schema References

Reference shared schemas across prompts:
Register schemas:

Tools in Prompts

Prompts can specify which tools to use:

Overriding at Runtime

Override prompt configuration when calling:

Streaming Prompt Responses

Prompts support streaming:

Rendering Without Execution

Render a prompt to see the final message without calling the model:
Useful for:
  • Testing prompt templates
  • Debugging variable substitution
  • Inspecting the exact request sent to models

Prompts as Tools

Convert a prompt into a tool that models can call:

Prompt File Organization

Organize prompts in directories:
Access nested prompts:

Partials (Shared Snippets)

Reuse common prompt sections:
Partials start with _ and are imported with {{> _partialName}}.

Best Practices

1. Use .prompt Files for Production

Store prompts as files for:
  • Version control
  • Team collaboration
  • Easy testing in Dev UI
  • Non-engineer editing

2. Define Clear Schemas

Always specify input and output schemas:

3. Use Variants for Testing

Test different approaches:
  • prompt.prompt - default version
  • prompt.concise.prompt - shorter responses
  • prompt.detailed.prompt - longer responses

4. Add Descriptions

Document your prompts:

5. Test with Real Data

Use the Dev UI to test prompts with real inputs before deploying.

Example: Complete Recipe Generator

Usage:

Next Steps

  • Learn about Tools - extending prompts with custom functions
  • Explore Flows - building workflows with prompts
  • See Models - understanding model behavior