validation

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package validation provides functionality for validating templates and inputs before execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMaxPromptLengthRule

func NewMaxPromptLengthRule(maxLength int) interfaces.InputValidationRule

NewMaxPromptLengthRule creates a new maximum prompt length rule

func NewNoCommandInjectionRule

func NewNoCommandInjectionRule() interfaces.InputValidationRule

NewNoCommandInjectionRule creates a new command injection rule

func NewNoJailbreakPatternRule

func NewNoJailbreakPatternRule() interfaces.InputValidationRule

NewNoJailbreakPatternRule creates a new jailbreak pattern rule

func NewNoSQLInjectionRule

func NewNoSQLInjectionRule() interfaces.InputValidationRule

NewNoSQLInjectionRule creates a new SQL injection rule

func NewNoSensitiveDataRule

func NewNoSensitiveDataRule() interfaces.InputValidationRule

NewNoSensitiveDataRule creates a new sensitive data rule

func NewSanitizeHTMLRule

func NewSanitizeHTMLRule() interfaces.InputValidationRule

NewSanitizeHTMLRule creates a new HTML sanitization rule

func NewSanitizeScriptRule

func NewSanitizeScriptRule() interfaces.InputValidationRule

NewSanitizeScriptRule creates a new script sanitization rule

Types

type InputValidator

type InputValidator struct {
	// contains filtered or unexported fields
}

InputValidator validates template inputs before sending to LLM providers

func NewInputValidator

func NewInputValidator(strictMode bool) *InputValidator

NewInputValidator creates a new input validator with default rules

func (*InputValidator) AddRule

AddRule adds a validation rule

func (*InputValidator) RemoveRule

func (v *InputValidator) RemoveRule(name string) bool

RemoveRule removes a validation rule by name

func (*InputValidator) SanitizePrompt

func (v *InputValidator) SanitizePrompt(prompt string) string

SanitizePrompt sanitizes a prompt to make it safer for execution

func (*InputValidator) SetStrictMode

func (v *InputValidator) SetStrictMode(strict bool)

SetStrictMode sets the strict mode

func (*InputValidator) ValidateTemplate

func (v *InputValidator) ValidateTemplate(ctx context.Context, template *format.Template) error

ValidateTemplate validates a template against all rules

type MaxPromptLengthRule

type MaxPromptLengthRule struct {
	// contains filtered or unexported fields
}

MaxPromptLengthRule checks if the prompt exceeds the maximum length

func (*MaxPromptLengthRule) GetDescription

func (r *MaxPromptLengthRule) GetDescription() string

GetDescription returns the description of the rule

func (*MaxPromptLengthRule) GetName

func (r *MaxPromptLengthRule) GetName() string

GetName returns the name of the rule

func (*MaxPromptLengthRule) Validate

func (r *MaxPromptLengthRule) Validate(ctx context.Context, template *format.Template) error

Validate validates a template against the rule

type NoCommandInjectionRule

type NoCommandInjectionRule struct{}

NoCommandInjectionRule checks for command injection patterns

func (*NoCommandInjectionRule) GetDescription

func (r *NoCommandInjectionRule) GetDescription() string

GetDescription returns the description of the rule

func (*NoCommandInjectionRule) GetName

func (r *NoCommandInjectionRule) GetName() string

GetName returns the name of the rule

func (*NoCommandInjectionRule) Validate

func (r *NoCommandInjectionRule) Validate(ctx context.Context, template *format.Template) error

Validate validates a template against the rule

type NoJailbreakPatternRule

type NoJailbreakPatternRule struct{}

NoJailbreakPatternRule checks for common jailbreak patterns

func (*NoJailbreakPatternRule) GetDescription

func (r *NoJailbreakPatternRule) GetDescription() string

GetDescription returns the description of the rule

func (*NoJailbreakPatternRule) GetName

func (r *NoJailbreakPatternRule) GetName() string

GetName returns the name of the rule

func (*NoJailbreakPatternRule) Validate

func (r *NoJailbreakPatternRule) Validate(ctx context.Context, template *format.Template) error

Validate validates a template against the rule

type NoSQLInjectionRule

type NoSQLInjectionRule struct{}

NoSQLInjectionRule checks for SQL injection patterns

func (*NoSQLInjectionRule) GetDescription

func (r *NoSQLInjectionRule) GetDescription() string

GetDescription returns the description of the rule

func (*NoSQLInjectionRule) GetName

func (r *NoSQLInjectionRule) GetName() string

GetName returns the name of the rule

func (*NoSQLInjectionRule) Validate

func (r *NoSQLInjectionRule) Validate(ctx context.Context, template *format.Template) error

Validate validates a template against the rule

type NoSensitiveDataRule

type NoSensitiveDataRule struct{}

NoSensitiveDataRule checks for sensitive data patterns

func (*NoSensitiveDataRule) GetDescription

func (r *NoSensitiveDataRule) GetDescription() string

GetDescription returns the description of the rule

func (*NoSensitiveDataRule) GetName

func (r *NoSensitiveDataRule) GetName() string

GetName returns the name of the rule

func (*NoSensitiveDataRule) Validate

func (r *NoSensitiveDataRule) Validate(ctx context.Context, template *format.Template) error

Validate validates a template against the rule

type SanitizeHTMLRule

type SanitizeHTMLRule struct{}

SanitizeHTMLRule checks for and sanitizes HTML content

func (*SanitizeHTMLRule) GetDescription

func (r *SanitizeHTMLRule) GetDescription() string

GetDescription returns the description of the rule

func (*SanitizeHTMLRule) GetName

func (r *SanitizeHTMLRule) GetName() string

GetName returns the name of the rule

func (*SanitizeHTMLRule) Validate

func (r *SanitizeHTMLRule) Validate(ctx context.Context, template *format.Template) error

Validate validates a template against the rule

type SanitizeScriptRule

type SanitizeScriptRule struct{}

SanitizeScriptRule checks for script tags and JavaScript code

func (*SanitizeScriptRule) GetDescription

func (r *SanitizeScriptRule) GetDescription() string

GetDescription returns the description of the rule

func (*SanitizeScriptRule) GetName

func (r *SanitizeScriptRule) GetName() string

GetName returns the name of the rule

func (*SanitizeScriptRule) Validate

func (r *SanitizeScriptRule) Validate(ctx context.Context, template *format.Template) error

Validate validates a template against the rule

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL