Skip to Content
GuidesCreate an Instruction

Create an Instruction

Build a production-quality instruction file that Copilot auto-applies whenever you edit matching files.

Prerequisites

  • FrootAI repo cloned
  • VS Code with GitHub Copilot Chat
  • Node.js 22+

Step 1: Understand the Frontmatter

Every instruction requires YAML frontmatter:

--- description: "What this instruction enforces (minimum 10 characters)" applyTo: "**/*.py" waf: - "security" - "reliability" ---
FieldRequiredValidation
descriptionβœ…Minimum 10 characters
applyToβœ…Valid glob pattern
wafNoValid WAF pillar names

Step 2: Choose Your applyTo Pattern

PatternMatchesUse Case
**/*.pyAll Python filesPython coding standards
**/*.{ts,tsx}TypeScript + TSXReact/TypeScript standards
**/*.bicepAll Bicep filesIaC best practices
solution-plays/01-*/**Play 01 files onlyPer-play targeting
**/infra/**/*.bicepInfra Bicep onlyInfrastructure rules

Step 3: Use the Scaffolder

node scripts/scaffold-primitive.js instruction

Follow the prompts:

  • Name: python-azure-waf
  • Description: β€œPython best practices for Azure AI services”
  • applyTo: **/*.py

Step 4: Write the Body

Include specific, actionable rules with code examples:

instructions/python-azure-waf.instructions.md
--- description: "Enforces Python best practices for Azure AI services β€” security, reliability, and cost optimization patterns." applyTo: "**/*.py" waf: - "security" - "reliability" - "cost-optimization" --- # Python Azure AI Coding Standards ## Security - Use `DefaultAzureCredential` for all Azure authentication: ​```python from azure.identity import DefaultAzureCredential credential = DefaultAzureCredential() ​``` - Never hardcode keys or connection strings ## Reliability - Add retry with exponential backoff on all Azure SDK calls: ​```python from tenacity import retry, stop_after_attempt, wait_exponential @retry(stop=stop_after_attempt(3), wait=wait_exponential(min=1, max=10)) async def call_openai(prompt: str) -> str: return await client.chat.completions.create(...) ​``` ## Cost Optimization - Always set `max_tokens` on LLM calls to prevent budget overruns - Route by complexity: GPT-4o-mini for classification, GPT-4o for generation
πŸ’‘

Copilot Follows Examples

Include concrete code patterns. Copilot learns from examples in the instruction body better than from abstract prose.

Step 5: Test in VS Code

  1. Open a .py file (matching your applyTo pattern)
  2. Start a Copilot Chat conversation
  3. Verify suggestions follow your instruction rules
  4. Ask @workspace "What instructions apply to this file?"

Step 6: Validate

npm run validate:primitives
⚠️

Keep Under 200 Lines

Instructions are loaded into the LLM context window. Shorter instructions use fewer tokens and get applied more reliably.

Advanced: Multi-Scope

Target multiple file types:

--- description: "Full-stack WAF standards" applyTo: "**/*.{ts,tsx,py}" waf: ["security", "reliability"] ---

Troubleshooting

ProblemFix
Instruction not appliedVerify glob matches your file
Validator says β€œdescription too short”Expand to 10+ characters
YAML parse errorAdd space after colons: description: "text"
Copilot ignores rulesAdd code examples instead of prose

See Also

Last updated on