---
name: "dspy-teleprompter-prompt-optimizer"
description: "Compile and optimize LLM prompts algorithmically with DSPy and metric evaluation."
metadata:
  author: "Stanford NLP"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "optimize prompts with dspy"
  - "write dspy signature"
  - "run dspy bootstrapfewshot"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# DSPy Teleprompter Programmatic Optimization

Replaces manual prompt tweaking with programmatic DSPy modules: dspy.Signature, dspy.Predict, dspy.ChainOfThought, and teleprompter optimizers (BootstrapFewShotWithRandomSearch, MIPROv2).

## When to Invoke
Invoke this skill whenever you need to:
- optimize prompts with dspy
- write dspy signature
- run dspy bootstrapfewshot

## Execution SOP & Rules
1. Define signatures declaratively: class CodeReview(dspy.Signature): diff = dspy.InputField(); ...
2. Implement custom metric functions returning float scores (e.g. F1, exact match, semantic similarity).
3. Use BootstrapFewShot to automatically synthesize effective few-shot demonstrations.
4. Save compiled programs using program.save('optimized_task.json') for production deployment.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
