Skip to main content

Creating Reusable Prompt Files

1. Creating .prompt.md Files

AI-assisted development tools often rely on structured prompt files to define reusable templates for generating code, documentation, or other content. These files typically use the .prompt.md extension to indicate their purpose and format.

Field Description Example
prompt The main prompt text that will be sent to the AI model. Generate a React component for displaying user profiles.
model The AI model to use for generating responses. gpt-4
temperature Controls randomness in the output (0.0 to 1.0). 0.7
max_tokens Maximum number of tokens to generate. 500
variables Optional placeholders for dynamic content. {user_role: "developer"}

Example: Basic .prompt.md File

# Prompt Template for Code Generation

## Prompt
Generate a React component for displaying user profiles.

## Model
gpt-4

## Temperature
0.7

## Max Tokens
500

## Variables
{user_role: "developer"}
Note: The .prompt.md format is designed to be human-readable and editable, making it easy to version control and share across teams.

2. Defining Prompt Front Matter

Field Description Example
name Name of the prompt template "Code Generation Template"
description Short description of the prompt's purpose "Generates JavaScript functions from natural language descriptions"
version Template version for tracking changes "1.0.0"
tags Array of tags for categorization ["javascript", "function-generation"]
author Creator of the prompt template "Jane Smith"
created ISO date when template was created "2026-01-15"
updated ISO date when template was last updated "2026-03-22"
parameters Configuration options for the prompt { "maxTokens": 500, "temperature": 0.7 }

Example: Front Matter in YAML

name: "Code Generation Template"
description: "Generates JavaScript functions from natural language descriptions"
version: "1.0.0"
tags:
  - javascript
  - function-generation
author: "Jane Smith"
created: "2026-01-15"
updated: "2026-03-22"
parameters:
  maxTokens: 500
  temperature: 0.7
Note: The front matter is typically placed at the top of a prompt file and uses YAML or JSON format to define metadata.

3. Parameterizing Prompt Templates

Parameter Type Description Usage Example Notes
input Represents the input data to be processed by the prompt template {{input}} Used to inject user-provided or dynamically generated content
context Provides additional context for the prompt to enhance understanding {{context}} Can include external data or previous conversation history
output_format Defines how the output should be formatted (e.g., JSON, XML) {{output_format}} Helps in structuring responses consistently
temperature Controls randomness in generation (0.0 to 1.0) {{temperature}} Higher values increase creativity; lower values favor consistency

Example: Parameterized Prompt Template


<prompt>
  You are an expert in {{topic}}. 
  Based on the following input: {{input}}, 
  provide a detailed explanation in {{output_format}} format.
</prompt>
Note: Parameterizing templates allows for dynamic content generation and reusability across different use cases.
Warning: Ensure that all parameters are properly sanitized to prevent injection attacks or unintended behavior.

4. Invoking Prompts with Slash Commands

Command Description Usage
/prompt list Lists all available prompt files /prompt list
/prompt run <name> Executes a specific prompt file /prompt run my-prompt
/prompt edit <name> Opens the prompt file in an editor /prompt edit my-prompt

Example: Running a Prompt via Slash Command

/prompt run code-review
Note: The prompt name must match exactly with the file name (without extension).

5. Sharing Prompt Files Across Repositories

Method Description Notes
Prompt Registry Centralized storage for prompt templates with versioning and metadata Supports search, tags, and access control
Git Submodules Include prompt files as submodules in other repositories Requires manual updates and synchronization
Package Managers Distribute prompt templates via npm, PyPI, or similar Enables versioning and dependency management
Cloud Storage Store prompt files in cloud services (e.g., AWS S3, GCP Cloud Storage) Requires authentication and access policies

Example: Using Git Submodules

git submodule add https://github.com/example/prompts.git shared-prompts
git submodule update --init --recursive

Example: Publishing to npm

{
  "name": "my-ai-prompts",
  "version": "1.0.0",
  "main": "./prompts/index.js",
  "files": [
    "prompts/"
  ]
}
Note: When sharing prompt files across repositories, ensure consistent versioning and documentation to avoid breaking changes in AI-assisted workflows.

6. Chaining Multiple Prompt Files

Chaining multiple prompt files allows you to build complex AI workflows by combining the outputs of one prompt file as input to another. This enables modular, reusable, and scalable AI-assisted development patterns.

File Description Usage
prompt1.json Initial prompt that generates a code snippet Used as input to next prompt in chain
prompt2.json Consumes output from prompt1 and adds documentation Processes the generated code to enhance it

Example: Chaining Prompt Files

{
  "name": "prompt1.json",
  "input": {
    "task": "generate a React component"
  },
  "output": {
    "code": "<div><p>Hello World</p></div>"
  }
}

Example: Chaining Prompt Files (Continued)

{
  "name": "prompt2.json",
  "input": {
    "code": "<div><p>Hello World</p></div>",
    "task": "add JSDoc comments"
  },
  "output": {
    "code": "<div><!-- JSDoc: A simple React component --><p>Hello World</p></div>"
  }
}
Note: Ensure that the output format of one prompt file matches the expected input format of the next in the chain.

Best Practices for Chaining Prompts

  • Use consistent data formats (e.g., JSON) across prompt files
  • Validate inputs and outputs at each step to prevent cascading errors
  • Document the purpose and structure of each prompt file in the chain

7. Restricting Tools per Prompt File

Tool Restriction Type Description Example
llm Model Selection Restricts the LLM used for generating responses "llm": "gpt-4"
tools Tool Access Lists allowed tools for use in the prompt "tools": ["web_search", "calculator"]
max_tokens Response Length Limits the maximum number of tokens in the response "max_tokens": 150
temperature Randomness Control Adjusts the randomness of the output (0.0 to 1.0) "temperature": 0.7

Example: Restricting Tools in a Prompt File

{
  "name": "Code Review Assistant",
  "llm": "gpt-4",
  "tools": [
    "web_search",
    "code_linter"
  ],
  "max_tokens": 200,
  "temperature": 0.5
}
Note: By restricting tools, you can ensure that only specific capabilities are used in your prompt files, enhancing security and consistency.

8. Testing Prompt File Outputs

Example: Basic Output Validation

// Sample prompt file output validation
const fs = require("fs");
const path = require("path");

// Read generated output
const outputPath = path.join(__dirname, "output.txt");
const output = fs.readFileSync(outputPath, "utf8");

// Validate content
if (output.includes("AI-generated content")) {
  console.log("✓ Output contains expected AI content");
} else {
  console.error("✗ Output missing expected AI content");
}
Test Type Description Implementation
Content Match Verifies that output matches expected content patterns output.includes("expected text")
Format Validation Ensures output adheres to required format (e.g., JSON, XML) JSON.parse(output)
Length Check Validates output length meets minimum/maximum thresholds output.length > 100
Note: Use assert or chai for unit testing in Node.js environments.

Example: Unit Test with Mocha

const assert = require("assert");
const fs = require("fs");

describe("Prompt Output Tests", () => {
  it("should generate valid JSON output", () => {
    const output = fs.readFileSync("output.json", "utf8");
    assert.doesNotThrow(() => JSON.parse(output));
  });
});

Testing Best Practices

  • Validate content patterns and structure
  • Check for format compliance (JSON, XML, etc.)
  • Ensure output length meets requirements
  • Use automated test frameworks (e.g., Mocha, Jest)

Was this article helpful?