Skip to main content

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

:::tip 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

:::warning 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โ€‹