Skip to main content
Glama

check_injection

Detect prompt injection attempts in text using 32+ rules for Chinese and English, including hidden character detection, to identify security threats.

Instructions

Detect prompt injection attempts in text. Supports 32+ rules for Chinese and English, with hidden character detection.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesText to scan for injection attempts
thresholdNoDetection threshold 0-100 (default: 60, lower = stricter)

Implementation Reference

  • The checkInjection method in ShellWard engine performs injection detection by matching input text against compiled rules and checking for hidden characters, calculating a risk score against a threshold.
    checkInjection(text: string, options?: { source?: string; threshold?: number }): InjectionResult {
      const threshold = options?.threshold ?? this.config.injectionThreshold
      const enforce = this.config.mode === 'enforce'
    
      const hiddenChars = detectHiddenChars(text)
      if (hiddenChars.length > 0) {
        this.log.write({
          level: 'MEDIUM',
          layer: 'L4',
          action: 'detect',
          detail: `Hidden characters detected: ${[...new Set(hiddenChars.map(h => h.name))].join(', ')} (${hiddenChars.length} chars)`,
        })
      }
    
      let score = 0
      const matched: { id: string; name: string; score: number }[] = []
      for (const rule of this.compiledRules) {
        if (rule.compiled.test(text)) {
          score += rule.riskScore
          matched.push({ id: rule.id, name: rule.name, score: rule.riskScore })
        }
      }
      if (hiddenChars.length > 3) score += 20
    
      if (score >= threshold) {
        this.log.write({
          level: score >= 80 ? 'CRITICAL' : 'HIGH',
          layer: 'L4',
          action: enforce ? 'block' : 'detect',
          detail: this.locale === 'zh'
            ? `检测到可能的提示词注入攻击!\n风险评分: ${score}/100\n匹配规则: ${matched.map(m => m.name).join(', ')}`
            : `Potential prompt injection detected!\nRisk score: ${score}/100\nMatched: ${matched.map(m => m.name).join(', ')}`,
        })
      }
    
      return { safe: score < threshold, score, threshold, matched, hiddenChars: hiddenChars.length }
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the safety burden and partially succeeds by disclosing capabilities: '32+ rules for Chinese and English' and 'hidden character detection.' However, it omits critical behavioral traits like whether the tool is read-only/safe, what the return format is (score, boolean, flagged segments), or performance characteristics.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences total. The first states core purpose (detection), the second adds capability context (rules, languages, hidden characters). Zero redundancy, compact and front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 2-parameter tool with complete schema coverage but no output schema and no annotations, the description adequately explains functionality and scope. However, it lacks disclosure of the return value structure or safety profile, which would be necessary for complete contextual understanding given the missing structured metadata.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema has 100% description coverage ('Text to scan...', 'Detection threshold...'), establishing a baseline of 3. The description adds no explicit parameter guidance, but none is needed given the complete schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with the specific verb 'Detect' and resource 'prompt injection attempts in text', clearly distinguishing it from sibling tools like check_command (likely command injection) or check_path (likely path traversal) by specifying the exact attack vector and medium.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage through specificity—limiting scope to 'prompt injection' and 'text' distinguishes it from other security checks—but provides no explicit when-to-use guidance, prerequisites, or direct comparisons to siblings like check_command or scan_data.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jnMetaCode/shellward'

If you have feedback or need assistance with the MCP directory API, please join our Discord server