Pre-LLM Validation
Use this skill to validate input before sending to LLMs. Ensures semantic coherence and domain relevance using the local knowledge graph.
When to Use
- Before making LLM API calls with user-provided context
- When validating that input contains relevant domain terms
- To check semantic coherence of multi-concept queries
- Pre-flight validation to reduce wasted LLM tokens
Validation Steps
1. Check Semantic Connectivity
# Validate that input terms are semantically connected
terraphim-agent validate --connectivity --json "your input text"
Output interpretation:
connected: true- Input is semantically coherent, proceed with LLM callconnected: false- Input spans unrelated concepts, consider warning user
2. Check Domain Coverage
# Find matched domain terms
terraphim-agent validate --json "your input text"
Output interpretation:
- High match count - Input is domain-relevant
- Low/zero matches - Input may be off-topic or use non-standard terminology
3. Suggest Corrections (Optional)
If terms aren't found, suggest alternatives:
# Get fuzzy suggestions for potential typos
terraphim-agent suggest --fuzzy "unclear term" --threshold 0.6
Workflow Example
# 1. Validate connectivity
RESULT=$(terraphim-agent validate --connectivity --json "$INPUT")
CONNECTED=$(echo "$RESULT" | jq -r '.connected')
if [ "$CONNECTED" = "false" ]; then
echo "Warning: Input spans unrelated concepts"
TERMS=$(echo "$RESULT" | jq -r '.matched_terms | join(", ")')
echo "Matched terms: $TERMS"
fi
# 2. Check domain coverage
MATCHES=$(terraphim-agent validate --json "$INPUT" | jq '.matched_count')
if [ "$MATCHES" -lt 2 ]; then
echo "Warning: Low domain coverage ($MATCHES terms)"
fi
# 3. Proceed with LLM call if validation passes
Integration with Hooks
This skill can be automated via the pre-tool-use hook:
terraphim-agent hook --hook-type pre-tool-use --input "$JSON"
Configuration
--role- Specify role for domain-specific validation--json- Machine-readable output for scripting--threshold- Similarity threshold for fuzzy matching (default: 0.6)
Best Practices
- Advisory Mode: Use validation results as warnings, not blockers
- Role Selection: Match role to the domain of the query
- Threshold Tuning: Adjust fuzzy threshold based on domain vocabulary
- Caching: Cache validation results for repeated queries