Skip to main content
Skill Lab can automatically generate trigger test cases for your skills using the Anthropic API. The sklab generate command reads your SKILL.md and produces ~13 test cases across all 4 trigger types (explicit, implicit, contextual, negative).

Overview

LLM-powered test generation:
  • Reads your skill’s name, description, and markdown content
  • Generates realistic test prompts for each trigger type
  • Creates .skill-lab/tests/triggers.yaml ready for execution
  • Shows token usage and cost estimates
Test generation requires the anthropic package. Install with: pip install skill-lab[generate]

Prerequisites

1

Install optional dependency

Install Skill Lab with the generate extra:
This installs the anthropic SDK (v0.39.0+).
2

Set API key

Export your Anthropic API key:
Get your key at console.anthropic.com.

Basic Usage

Generate Tests

The command will:
  1. Read SKILL.md (name, description, body content)
  2. Call the Anthropic API to generate test cases
  3. Write .skill-lab/tests/triggers.yaml
  4. Display token usage and cost

Example Output

After generation, review the generated tests in .skill-lab/tests/triggers.yaml. You can edit them manually to add domain-specific test cases.

Command Options

Specify Model

Use a specific Anthropic model:
Supported models:
  • claude-haiku-4-5-20251001 (default): Fast, cheap, good quality
  • claude-sonnet-4-5-20250929: Higher quality, more expensive
  • claude-opus-4-6: Highest quality, most expensive

Set Default Model

Set a global default model via environment variable:
Precedence: --model flag > SKLAB_MODEL env var > default (Haiku)

Force Overwrite

Overwrite existing test file without prompting:
By default, sklab generate prompts before overwriting .skill-lab/tests/triggers.yaml.

Generated Test Structure

The generated triggers.yaml file contains ~13 test cases:

Test Distribution

How It Works

1

Skill content extraction

Skill Lab reads your SKILL.md:
  • Extracts name and description from YAML frontmatter
  • Reads the markdown body (up to 4,000 characters)
2

LLM prompt construction

Builds a system prompt with:
  • Instructions to generate trigger tests
  • Expected YAML schema
  • Examples of good test cases
3

API call

Calls the Anthropic API with:
  • System prompt: Instructions for test generation
  • User message: Your skill’s name, description, and content
  • Model: Default (claude-haiku-4-5-20251001) or specified via --model
4

Response parsing

Parses and validates the LLM response:
  • Strips markdown code fences (if present)
  • Parses YAML structure
  • Validates required fields (id, type, prompt, expected)
  • Forces correct skill name
5

File writing

Writes .skill-lab/tests/triggers.yaml:
  • Creates .skill-lab/tests/ directory if needed
  • Prompts before overwriting (unless --force)

Token Usage and Pricing

Token Estimates

Skill Lab displays token usage after generation:
  • Input tokens: System prompt + your skill content
  • Output tokens: Generated YAML test cases
  • Cost: Calculated using current Anthropic pricing

Pricing (as of Feb 2025)

Pricing is embedded in src/skill_lab/triggers/generator.py and may change. Check Anthropic pricing for current rates.

Customizing Generated Tests

After generation, you can edit .skill-lab/tests/triggers.yaml manually:

Add Domain-Specific Tests

Refine Negative Tests

Negative tests are crucial for avoiding false positives:

Adjust for Prerequisites

If your skill has prerequisites, add tests that check activation logic:

Best Practices

Write Clear Skill Descriptions

The quality of generated tests depends on your skill’s description:
Clear descriptions help the LLM generate:
  • More realistic implicit/contextual prompts
  • Better negative tests (understanding boundaries)
  • Domain-specific vocabulary

Review Generated Tests

Always review the generated tests before running them:
  1. Check for duplicate or redundant tests
  2. Verify negative tests cover adjacent domains
  3. Ensure contextual tests are realistic
  4. Add missing edge cases

Iterate and Regenerate

If the initial generation is poor:
  1. Improve your skill description in SKILL.md
  2. Add more examples to the skill body
  3. Regenerate: sklab generate --force

Troubleshooting

”ANTHROPIC_API_KEY environment variable is not set”

Solution: Export your API key:
Or add to your shell profile (~/.bashrc, ~/.zshrc):

“The ‘anthropic’ package is required for test generation”

Solution: Install the optional dependency:

Generated Tests Are Low Quality

Solutions:
  1. Use a better model: --model claude-sonnet-4-5-20250929
  2. Improve skill description: Add more context and examples to SKILL.md
  3. Manually edit: Refine the generated tests in .skill-lab/tests/triggers.yaml

”Failed to parse generated YAML”

The LLM returned invalid YAML. Solutions:
  1. Try regenerating: sklab generate --force
  2. Switch to Sonnet: --model claude-sonnet-4-5-20250929
  3. If persistent, file a bug report with your skill content

Workflow Example

1

Create skill

Write your SKILL.md with clear name, description, and examples:
2

Generate tests

Auto-generate trigger tests:
3

Review and refine

Review .skill-lab/tests/triggers.yaml and add custom tests:
4

Run tests

Execute the generated tests:
5

Iterate

If tests fail or are low quality:
  1. Update SKILL.md description
  2. Regenerate: sklab generate --force
  3. Re-run: sklab trigger

Next Steps

Trigger Testing

Learn how to run and interpret trigger test results

Static Analysis

Validate skill structure and content quality