Documentation-Accurate Code Generation
by @tobisamaa
Generate code that references actual documentation, preventing hallucination bugs. ALWAYS loads docs first, validates against API signatures, and verifies co...
clawhub install doc-accurate-codegenπ About This Skill
name: doc-accurate-codegen version: "1.0.0" description: "Generate code that references actual documentation, preventing hallucination bugs. ALWAYS loads docs first, validates against API signatures, and verifies correctness. Use for ANY code generation, API usage, or configuration creation." metadata: openclaw: emoji: "π" requires: bins: ["curl", "jq", "git"] env: ["BRAVE_API_KEY"] install: - id: npm kind: node package: axios bins: ["axios"]
Documentation-Accurate Code Generation
CRITICAL: This skill prevents LLM hallucination by enforcing documentation reference.
When to Use
Core Philosophy
NEVER generate code from memory. ALWAYS reference documentation.
The Problem
The Solution
1. Load documentation FIRST β Before writing any code 2. Extract API signatures β Get actual method signatures 3. Generate from docs β Use real API data 4. Validate against docs β Check generated code matches 5. Reference tracking β Document which docs were usedWorkflow
1. IDENTIFY β What code/API/tool is needed?
2. LOCATE β Find documentation source
3. LOAD β Fetch and parse documentation
4. EXTRACT β Pull API signatures, parameters, examples
5. GENERATE β Create code using actual docs
6. VALIDATE β Check code matches documentation
7. REFERENCE β Track what docs were used
Documentation Sources
1. OpenClaw Internal Docs
C:\Users\clipp\AppData\Roaming\npm\node_modules\openclaw\docsread tool2. Tool Documentation
--help flagsman web_fetch to get docs3. API Documentation
web_fetch4. Code Examples
Process for Code Generation
Step 1: Documentation Discovery
# For OpenClaw tools
read("openclaw-docs-path/tool-name.md")For external tools
web_fetch("https://docs.tool.com/api")For local tools
exec("tool --help")
Step 2: API Signature Extraction
# Extract:
Method names
Parameters (names, types, required/optional)
Return types
Error handling
Examples
Version information
Step 3: Code Generation
# Generate code using actual API data
def generate_from_docs(api_docs):
# Use real method names
# Use real parameter names
# Use real return types
# Include error handling from docs
# Add docstrings from docs
pass
Step 4: Validation
def validate_against_docs(code, api_docs):
# Check method names match
# Check parameter names match
# Check types match
# Check return types match
# Verify no hallucinated methods
pass
Quick Actions
codegen β Generate code with doc referencevalidate β Check code against docsdoc-lookup β Load and display documentationapi-extract β Extract API signaturesUsage Examples
"Generate code to use the OpenClaw sessions_spawn tool"
Process: Load docs β Extract API β Generate β Validate
"Create a Python script using the requests library"
Process: Fetch requests docs β Extract API β Generate β Validate
"Write configuration for OpenClaw channels"
Process: Load config docs β Extract format β Generate β Validate
Validation Rules
1. Method Name Validation
2. Parameter Validation
3. Return Type Validation
4. Configuration Validation
Error Prevention
Common Hallucination Patterns
1. Non-existent methods β Methods that don't exist 2. Wrong parameter names β Hallucinated parameter names 3. Wrong types β Incorrect parameter/return types 4. Missing error handling β Ignoring documented errors 5. Wrong configuration format β Incorrect config structurePrevention Strategies
1. Always load docs first β Never generate from memory 2. Extract actual signatures β Don't guess API shape 3. Validate everything β Check against real docs 4. Reference tracking β Know which docs were used 5. Test with real APIs β Verify code actually worksIntegration Points
With Other Skills
With OpenClaw Tools
--help for docsReference Tracking
Format
# Code Generation ReferenceGenerated Code
File: path/to/file.py
Generated: 2026-02-23
Tool: doc-accurate-codegen Documentation Sources
1. OpenClaw Tool Docs: /docs/tools/exec.md
2. API Reference: https://docs.example.com/api
3. Examples: /examples/exec-usage.pyValidation
β
Method names validated
β
Parameters validated
β
Return types validated
β
Error handling validated Notes
Using exec tool with sandbox mode
All parameters from official docs
Error handling from API reference
Output Template
When generating code, always include:
# Code generated with documentation reference
Source: [documentation URL or path]
Validated: [timestamp]
API Version: [version if available]
def function_name():
"""
[Docstring from actual documentation]
Source: [link to docs]
Parameters: [from docs]
Returns: [from docs]
"""
# Implementation using actual API
pass
Best Practices
1. Docs First, Always β Never generate without loading docs 2. Exact Matches β Use exact names, types, formats from docs 3. Validate Everything β Check all generated code 4. Track References β Document which docs were used 5. Test Real APIs β Actually run the code to verify 6. Update Regularly β Re-check docs as APIs evolve 7. Error Handling β Include all documented errors 8. Examples β Reference working examples from docs
Common Pitfalls
1. Assuming API stability β APIs change, always re-check docs 2. Memory over docs β Trust docs, not memory 3. Partial loading β Load complete documentation 4. No validation β Always validate generated code 5. Missing references β Always track doc sources
Success Metrics
Advanced Features
1. Automatic Doc Loading
2. API Change Detection
3. Multi-Source Validation
4. Example Extraction
Integration with OpenClaw
Tool Documentation
# Get tool help
exec("tool --help")Read tool docs
read("openclaw/docs/tools/tool-name.md")Check tool examples
read("openclaw/examples/tool-usage.md")
Skill Documentation
# Read skill docs
read("skills/skill-name/SKILL.md")Check skill examples
read("skills/skill-name/examples/")
Configuration Documentation
# Read config docs
read("openclaw/docs/configuration.md")Check config examples
read("openclaw/examples/config/")
Remember: This skill exists because LLMs hallucinate. ALWAYS use it for code generation. The only way to prevent bugs is to reference actual documentation.
β‘ When to Use
π Tips & Best Practices
1. Docs First, Always β Never generate without loading docs 2. Exact Matches β Use exact names, types, formats from docs 3. Validate Everything β Check all generated code 4. Track References β Document which docs were used 5. Test Real APIs β Actually run the code to verify 6. Update Regularly β Re-check docs as APIs evolve 7. Error Handling β Include all documented errors 8. Examples β Reference working examples from docs