Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Extract, validate, and test code samples in documentation. Verify syntax, execute samples, check outputs, validate imports, and ensure code samples are up-to-date with current APIs.
.claude/skills/a5c-ai-code-sample-validator/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | -11% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 97% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 99% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 229% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 137% | 0% |
Extract, validate, and test code samples in documentation.
Invoke this skill when you need to:
| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | inputPath | string | Yes | Path to documentation file or directory | | action | string | Yes | extract, validate, execute, format | | languages | array | No | Filter by language (js, python, etc.) | | outputDir | string | No | Directory for extracted runnable code | | timeout | number | No | Execution timeout in seconds | | config | object | No | Language-specific configuration |
json{ "inputPath": "./docs", "action": "validate", "languages": ["javascript", "python"], "timeout": 30 }
json{ "summary": { "total": 45, "passed": 42, "failed": 2, "skipped": 1 }, "files": [ { "file": "docs/quickstart.md", "samples": [ { "language": "javascript", "line": 15, "status": "passed", "syntaxValid": true, "executionResult": { "success": true, "output": "Hello, World!", "duration": 125 } }, { "language": "python", "line": 45, "status": "failed", "syntaxValid": true, "executionResult": { "success": false, "error": "ModuleNotFoundError: No module named 'requests'", "suggestion": "Add 'requests' to test dependencies" } } ] } ], "issues": [ { "file": "docs/api/users.md", "line": 78, "language": "typescript", "issue": "Type error: Property 'user' does not exist on type 'Response'", "code": "const name = response.user.name;", "suggestion": "Update to use 'response.data.user.name'" } ] }
`markdown
// This block will be extracted and validated const client = new Client({ apiKey: 'test' }); const result = await client.query('Hello'); console.log(result);
from mypackage import Client
client = Client(api_key='test') result = client.query('Hello') print(result)
echo "Not validated"
// This block is marked as runnable export function greet(name) { return Hello, ${name}!; }
json{ "extract": { "includeLanguages": ["javascript", "typescript", "python", "go"], "excludeLanguages": ["bash", "shell", "text"], "directives": { "skip": ["skip-validation", "no-test"], "runnable": ["runnable", "test"], "expectError": ["expect-error"] }, "metaPatterns": { "title": "title=\"([^\"]+)\"", "filename": "filename=\"([^\"]+)\"" } } }
javascript// validator-config.js module.exports = { javascript: { parser: 'babel', parserOptions: { ecmaVersion: 2024, sourceType: 'module' }, execute: { runtime: 'node', timeout: 10000, setup: ` global.fetch = require('node-fetch'); process.env.API_KEY = 'test-key'; ` }, format: { tool: 'prettier', config: { semi: true, singleQuote: true, trailingComma: 'es5' } } }, typescript: { compiler: 'tsc', compilerOptions: { target: 'ES2022', module: 'ESNext', strict: true }, execute: { runtime: 'ts-node', timeout: 15000 } } };
python# validator_config.py PYTHON_CONFIG = { 'version': '3.11', 'execute': { 'timeout': 30, 'setup': ''' import os os.environ['API_KEY'] = 'test-key' ''', 'virtualenv': '.venv' }, 'format': { 'tool': 'black', 'config': { 'line_length': 88, 'target_version': ['py311'] } }, 'lint': { 'tool': 'ruff', 'rules': ['E', 'F', 'W'] } }
go// validator_config.go package main var GoConfig = Config{ Version: "1.21", Execute: ExecuteConfig{ Timeout: 30, Build: true, Run: true, }, Format: FormatConfig{ Tool: "gofmt", }, Lint: LintConfig{ Tool: "golangci-lint", Rules: []string{"govet", "errcheck", "staticcheck"}, }, }
javascript// Generated from docs/quickstart.md const { Client } = require('@example/sdk'); describe('Documentation Code Samples', () => { describe('quickstart.md', () => { test('Line 15: Basic client usage', async () => { const client = new Client({ apiKey: 'test' }); const result = await client.query('Hello'); expect(result).toBeDefined(); }); test('Line 45: Error handling', async () => { const client = new Client({ apiKey: 'invalid' }); await expect(client.query('Hello')).rejects.toThrow('Invalid API key'); }); }); });
json{ "testGeneration": { "framework": "jest", "outputDir": "tests/docs", "filePattern": "{docfile}.test.js", "imports": [ "const { Client } = require('@example/sdk');", "const { mockServer } = require('./mocks');" ], "beforeAll": "await mockServer.start();", "afterAll": "await mockServer.stop();", "assertions": { "outputMatch": true, "noThrow": true, "typeCheck": true } } }
yamlname: Validate Documentation on: push: paths: - 'docs/**/*.md' pull_request: paths: - 'docs/**/*.md' jobs: validate-code-samples: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: '20' - uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install dependencies run: | npm ci pip install -r requirements-docs.txt - name: Validate code samples run: | node scripts/validate-docs.js \ --input docs/ \ --languages javascript,python \ --report validation-report.json - name: Upload report if: always() uses: actions/upload-artifact@v4 with: name: validation-report path: validation-report.json - name: Check for failures run: | if jq '.summary.failed > 0' validation-report.json | grep -q true; then echo "Code sample validation failed" jq '.issues' validation-report.json exit 1 fi
javascriptconst prettier = require('prettier'); async function validateFormatting(code, language) { const options = { parser: getParser(language), semi: true, singleQuote: true, trailingComma: 'es5', }; try { const formatted = await prettier.format(code, options); const isFormatted = code === formatted; return { valid: isFormatted, formatted: formatted, diff: isFormatted ? null : generateDiff(code, formatted), }; } catch (error) { return { valid: false, error: error.message, }; } }
pythonimport black import difflib def validate_formatting(code: str) -> dict: try: mode = black.Mode( target_versions={black.TargetVersion.PY311}, line_length=88, ) formatted = black.format_str(code, mode=mode) is_formatted = code == formatted return { 'valid': is_formatted, 'formatted': formatted, 'diff': None if is_formatted else list( difflib.unified_diff( code.splitlines(), formatted.splitlines(), lineterm='' ) ) } except black.InvalidInput as e: return { 'valid': False, 'error': str(e) }
json{ "devDependencies": { "@babel/parser": "^7.23.0", "prettier": "^3.0.0", "typescript": "^5.3.0", "ts-node": "^10.9.0", "jest": "^29.7.0", "gray-matter": "^4.0.0" } }
bash# Validate all samples node scripts/validate-docs.js --input docs/ # Extract and save runnable code node scripts/validate-docs.js --input docs/ --action extract --output tests/samples/ # Generate test files node scripts/validate-docs.js --input docs/ --action generate-tests --output tests/docs/ # Check formatting only node scripts/validate-docs.js --input docs/ --action format-check
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 46,233 | 19,024 | -59% | 1 | 1 | 0% | 6,323 | 5,652 | -11% | 0 | 0 | — |
case-02 | fail→fail | 23,772 | 23,404 | -2% | 1 | 1 | 0% | 3,851 | 7,085 | +84% | 0 | 0 | — |
case-03 | fail→fail | 35,323 | 21,067 | -40% | 1 | 1 | 0% | 5,271 | 6,617 | +26% | 0 | 0 | — |
case-04 | fail→pass | 31,755 | 11,605 | -63% | 1 | 1 | 0% | 2,063 | 4,068 | +97% | 0 | 0 | — |
case-05 | fail→pass | 24,850 | 20,143 | -19% | 1 | 1 | 0% | 2,573 | 5,131 | +99% | 0 | 0 | — |
case-06 | pass→pass | 17,839 | 9,973 | -44% | 1 | 1 | 0% | 2,049 | 3,702 | +81% | 0 | 0 | — |
case-07 | pass→pass | 15,556 | 8,696 | -44% | 1 | 1 | 0% | 1,901 | 4,343 | +128% | 0 | 0 | — |
case-08 | pass→pass | 14,431 | 2,902 | -80% | 1 | 1 | 0% | 2,279 | 3,465 | +52% | 0 | 0 | — |
case-09 | fail→pass | 12,877 | 10,473 | -19% | 1 | 1 | 0% | 1,120 | 3,688 | +229% | 0 | 0 | — |
case-10 | pass→pass | 12,205 | 11,398 | -7% | 1 | 1 | 0% | 1,204 | 4,097 | +240% | 0 | 0 | — |
case-11 | fail→fail | 15,521 | 9,822 | -37% | 1 | 1 | 0% | 2,385 | 4,720 | +98% | 0 | 0 | — |
case-12 | fail→pass | 10,510 | 11,922 | +13% | 1 | 1 | 0% | 1,836 | 4,354 | +137% | 0 | 0 | — |
case-13 | fail→pass | 17,654 | 7,047 | -60% | 1 | 1 | 0% | 2,403 | 3,343 | +39% | 0 | 0 | — |
case-14 | fail→pass | 13,950 | 4,350 | -69% | 1 | 1 | 0% | 2,280 | 3,800 | +67% | 0 | 0 | — |
case-15 | fail→pass | 18,743 | 15,656 | -16% | 1 | 1 | 0% | 2,311 | 4,850 | +110% | 0 | 0 | — |
case-16 | pass→pass | 18,564 | 10,077 | -46% | 1 | 1 | 0% | 2,471 | 3,882 | +57% | 0 | 0 | — |
case-17 | fail→pass | 13,851 | 11,772 | -15% | 1 | 1 | 0% | 2,504 | 4,338 | +73% | 0 | 0 | — |
case-18 | fail→pass | 19,309 | 2,386 | -88% | 1 | 1 | 0% | 3,342 | 3,409 | +2% | 0 | 0 | — |
case-19 | fail→pass | 16,721 | 2,869 | -83% | 1 | 1 | 0% | 1,907 | 3,507 | +84% | 0 | 0 | — |
case-20 | pass→pass | 21,557 | 19,546 | -9% | 1 | 1 | 0% | 3,489 | 5,925 | +70% | 0 | 0 | — |
case-21 | pass→pass | 12,113 | 13,957 | +15% | 1 | 1 | 0% | 2,350 | 4,682 | +99% | 0 | 0 | — |
case-22 | pass→pass | 10,284 | 12,965 | +26% | 1 | 1 | 0% | 1,740 | 5,404 | +211% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +50 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.