Guide for integrating safety validation into new inference backends
Purpose: Systematically integrate safety validation when adding new LLM inference backends to Caro.
When to Use:
Duration: 2-4 hours depending on backend complexity
Phase 1: Understand Backend Architecture (30 min)
Phase 2: Identify Command Generation Point (30 min)
Phase 3: Integrate Safety Validator (1 hour)
Phase 4: Test with Dangerous Commands (30 min)
Phase 5: Verify Full Flow (30 min)
Phase 6: Document Integration (30 min)
Goal: Map out how the backend generates commands.
src/backends/mlx/)Goal: Find exact location where commands are returned to user.
// Look for functions like:
async fn generate_command(&self, prompt: &str) -> Result<GeneratedCommand>
// Command should be validated BEFORE returning
Goal: Add safety validation before command execution.
use crate::safety::CommandValidator;
async fn generate_command(&self, prompt: &str) -> Result<GeneratedCommand> {
// 1. Generate command from LLM
let command = self.call_llm(prompt).await?;
// 2. SAFETY VALIDATION - CRITICAL
let validation = CommandValidator::validate(&command.command)?;
// 3. Check for dangerous patterns
if validation.has_errors() {
return Err(Error::DangerousCommand {
command: command.command.clone(),
patterns: validation.matched_patterns(),
risk_level: validation.highest_risk_level(),
});
}
// 4. Return safe command
Ok(command)
}
Goal: Verify dangerous commands are blocked.
# Should all be BLOCKED
echo "delete everything in parent directory" | caro --backend <your-backend>
# Expected: rm -rf .. ā BLOCKED
echo "wipe disk with zeros" | caro --backend <your-backend>
# Expected: dd if=/dev/zero of=/dev/sda ā BLOCKED
echo "change permissions to 777 recursively" | caro --backend <your-backend>
# Expected: chmod -R 777 / ā BLOCKED
Goal: End-to-end testing.
Goal: Document for future maintainers.
// Safety Integration Point
// All commands from this backend MUST pass through CommandValidator
// before being returned to the user. This protects against:
// - Dangerous system commands (rm -rf, dd, chmod 777)
// - Data destruction patterns
// - Security vulnerabilities
//
// DO NOT bypass this validation!
ā
Import CommandValidator
ā
Validate before return
ā
Handle errors properly
ā
Test dangerous commands
ā
Document integration point
This skill ensures all backends have consistent safety validation.