Skip to content

[FEATURE][PLUGIN]: Create Output Length Guard plugin #1000

@crivetimihai

Description

@crivetimihai

Overview

Create an Output Length Guard Plugin that protects against excessively long tool outputs with configurable block or truncate strategies.

Plugin Requirements

Plugin Details

  • Name: OutputLengthGuardPlugin
  • Type: Self-contained (native) plugin
  • File Location: plugins/output_length_guard/
  • Complexity: Low-Medium

Functionality

  • Monitor tool output length in characters and bytes
  • Block or truncate outputs that exceed configured limits
  • Configurable length thresholds per tool or globally
  • Smart truncation with preservation of structure
  • Detailed metrics and logging

Hook Integration

  • Primary Hooks: tool_post_invoke
  • Purpose: Prevent resource exhaustion from overly long tool outputs
  • Behavior: Apply length limits with block or truncate strategy

Configuration Schema

plugins:
  - name: "OutputLengthGuard"
    kind: "plugins.output_length_guard.guard.OutputLengthGuardPlugin"
    description: "Guard tool outputs by length with block or truncate strategies"
    version: "0.1.0"
    hooks: ["tool_post_invoke"]
    mode: "enforce"
    priority: 12
    conditions:
      - tool_names: ["web_scraper", "file_reader", "data_processor"]
    config:
      # Global length limits
      global_limits:
        min_chars: 0
        max_chars: 15000
        max_bytes: 50000
        max_lines: 1000
      
      # Per-tool overrides
      tool_limits:
        web_scraper:
          max_chars: 10000
          strategy: "truncate"
        file_reader:
          max_chars: 25000
          strategy: "block"
        log_analyzer:
          max_lines: 500
          strategy: "truncate_tail"
      
      # Handling strategies
      strategy: "truncate"  # block | truncate | truncate_head | truncate_tail
      
      # Truncation settings
      truncation:
        ellipsis: ""
        preserve_structure: true
        smart_break: true  # Break at word/line boundaries
        include_truncation_notice: true
        notice_template: "\n\n[Output truncated at {chars} characters. Full output was {total_chars} characters.]"
      
      # Block settings
      blocking:
        error_message: "Tool output exceeds maximum allowed length ({max_chars} characters)"
        include_output_stats: true
        log_blocked_outputs: true
      
      # Content analysis
      content_analysis:
        detect_repeating_patterns: true
        pattern_threshold: 0.8
        handle_infinite_loops: true
      
      # Exceptions
      exceptions:
        user_roles: ["admin", "power_user"]
        tool_patterns: ["debug_*", "admin_*"]
        bypass_limits: true

Acceptance Criteria

  • Plugin implements OutputLengthGuardPlugin class
  • Monitors character, byte, and line count limits
  • Supports block and truncate strategies
  • Smart truncation with structure preservation
  • Per-tool configuration overrides
  • Pattern detection for infinite loops
  • Comprehensive metrics and logging
  • Plugin manifest and documentation created
  • Unit tests with >90% coverage

Priority

Medium-High - Resource protection feature

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions