Detect unsafe code patterns in LLM outputs using TrueFoundry’s built-in Code Safety Linter guardrail.
This guide explains how to use TrueFoundry’s built-in Code Safety Linter guardrail to detect and block potentially dangerous code patterns in LLM outputs.
Code Safety Linter is a built-in TrueFoundry guardrail that analyzes code in LLM responses to detect unsafe patterns that could pose security risks when executed. It runs directly within the AI Gateway without requiring external API calls.
Validation-Only Mode: Code Safety Linter operates in validation mode, detecting and blocking unsafe code rather than modifying it—ensuring code integrity while maintaining security.
The Code Safety Linter detects the following categories of unsafe code patterns. Each pattern is designed to identify potentially dangerous code constructs that could pose security risks.
with open('data.txt', 'r') as f: content = f.read()# Using pathlib for safe file handlingfrom pathlib import Pathdata = Path('config.json').read_text()
Result: Allowed - No unsafe patterns detected
JavaScript: Safe async operations
const fs = require('fs').promises;const data = await fs.readFile('config.json', 'utf8');
Result: Allowed - No unsafe patterns detected
SQL: Safe queries
SELECT * FROM users WHERE id = ?;UPDATE users SET name = ? WHERE id = ?;