Documentation
¶
Overview ¶
Package interceptors provides middleware components for dspy-go modules and agents.
Package interceptors provides middleware components for dspy-go modules and agents.
Index ¶
- func ApplyXMLInterceptors(module core.Module, config XMLConfig) error
- func CachingModuleInterceptor(cache Cache, ttl time.Duration) core.ModuleInterceptor
- func CachingToolInterceptor(cache Cache, ttl time.Duration) core.ToolInterceptor
- func ChainOfThoughtStructuredInterceptor(config ChainOfThoughtStructuredConfig) core.ModuleInterceptor
- func CircuitBreakerAgentInterceptor(cb *CircuitBreaker) core.AgentInterceptor
- func CircuitBreakerModuleInterceptor(cb *CircuitBreaker) core.ModuleInterceptor
- func CircuitBreakerToolInterceptor(cb *CircuitBreaker) core.ToolInterceptor
- func CreateXMLInterceptorChain(config XMLConfig, additionalInterceptors ...core.ModuleInterceptor) []core.ModuleInterceptor
- func LoggingAgentInterceptor() core.AgentInterceptor
- func LoggingModuleInterceptor() core.ModuleInterceptor
- func LoggingToolInterceptor() core.ToolInterceptor
- func MetricsAgentInterceptor() core.AgentInterceptor
- func MetricsModuleInterceptor() core.ModuleInterceptor
- func MetricsToolInterceptor() core.ToolInterceptor
- func NativeFunctionCallingInterceptor(config FunctionCallingConfig) core.ModuleInterceptor
- func ParseXMLAction(actionStr string, config XMLConfig) (toolName string, arguments map[string]interface{}, err error)
- func RateLimitingAgentInterceptor(limit int, window time.Duration) core.AgentInterceptor
- func RateLimitingToolInterceptor(limit int, window time.Duration) core.ToolInterceptor
- func RetryAgentInterceptor(config RetryConfig) core.AgentInterceptor
- func RetryModuleInterceptor(config RetryConfig) core.ModuleInterceptor
- func RetryToolInterceptor(config RetryConfig) core.ToolInterceptor
- func SanitizingAgentInterceptor() core.AgentInterceptor
- func SanitizingModuleInterceptor() core.ModuleInterceptor
- func SanitizingToolInterceptor() core.ToolInterceptor
- func StructuredOutputInterceptor(config StructuredOutputConfig) core.ModuleInterceptor
- func TimeoutAgentInterceptor(timeout time.Duration) core.AgentInterceptor
- func TimeoutModuleInterceptor(timeout time.Duration) core.ModuleInterceptor
- func TimeoutToolInterceptor(timeout time.Duration) core.ToolInterceptor
- func TracingAgentInterceptor() core.AgentInterceptor
- func TracingModuleInterceptor() core.ModuleInterceptor
- func TracingToolInterceptor() core.ToolInterceptor
- func ValidationAgentInterceptor(config ValidationConfig) core.AgentInterceptor
- func ValidationModuleInterceptor(config ValidationConfig) core.ModuleInterceptor
- func ValidationToolInterceptor(config ValidationConfig) core.ToolInterceptor
- func WithAuthorizationContext(ctx context.Context, authCtx *AuthorizationContext) context.Context
- func XMLFormatModuleInterceptor(config XMLConfig) core.ModuleInterceptor
- func XMLModuleInterceptor(config XMLConfig) core.ModuleInterceptor
- func XMLParseModuleInterceptor(config XMLConfig) core.ModuleInterceptor
- type AuthorizationContext
- type AuthorizationInterceptor
- func (ai *AuthorizationInterceptor) AgentAuthorizationInterceptor() core.AgentInterceptor
- func (ai *AuthorizationInterceptor) ModuleAuthorizationInterceptor() core.ModuleInterceptor
- func (ai *AuthorizationInterceptor) SetPolicy(resource string, policy AuthorizationPolicy)
- func (ai *AuthorizationInterceptor) ToolAuthorizationInterceptor() core.ToolInterceptor
- type AuthorizationPolicy
- type Cache
- type CacheEntry
- type ChainOfThoughtStructuredConfig
- type CircuitBreaker
- type CircuitState
- type FunctionCallingConfig
- type FunctionCallingReActAdapter
- type MemoryCache
- type ParsedSignature
- type RateLimiter
- type RetryConfig
- type StructuredOutputAdapter
- func (a *StructuredOutputAdapter) GetInterceptor() core.ModuleInterceptor
- func (a *StructuredOutputAdapter) WithCustomInstructions(instructions string) *StructuredOutputAdapter
- func (a *StructuredOutputAdapter) WithStrictSchema() *StructuredOutputAdapter
- func (a *StructuredOutputAdapter) WithoutDescriptions() *StructuredOutputAdapter
- type StructuredOutputConfig
- type ValidationConfig
- type XMLConfig
- func (c XMLConfig) GetTagName(fieldName string) string
- func (c XMLConfig) WithCustomTag(fieldName, tagName string) XMLConfig
- func (c XMLConfig) WithFallback(fallback bool) XMLConfig
- func (c XMLConfig) WithMaxDepth(depth int) XMLConfig
- func (c XMLConfig) WithMaxSize(size int64) XMLConfig
- func (c XMLConfig) WithPreserveWhitespace(preserve bool) XMLConfig
- func (c XMLConfig) WithStrictParsing(strict bool) XMLConfig
- func (c XMLConfig) WithTimeout(timeout time.Duration) XMLConfig
- func (c XMLConfig) WithTypeHints(hints bool) XMLConfig
- func (c XMLConfig) WithValidation(validate bool) XMLConfig
- type XMLParser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyXMLInterceptors ¶
ApplyXMLInterceptors applies XML format and parse interceptors to a module. This is a convenience function for modules that implement InterceptableModule.
func CachingModuleInterceptor ¶
func CachingModuleInterceptor(cache Cache, ttl time.Duration) core.ModuleInterceptor
CachingModuleInterceptor creates an interceptor that caches module results. It uses input data and module info to generate cache keys.
func CachingToolInterceptor ¶
func CachingToolInterceptor(cache Cache, ttl time.Duration) core.ToolInterceptor
CachingToolInterceptor creates an interceptor that caches tool results.
func ChainOfThoughtStructuredInterceptor ¶
func ChainOfThoughtStructuredInterceptor(config ChainOfThoughtStructuredConfig) core.ModuleInterceptor
ChainOfThoughtStructuredInterceptor creates an interceptor specifically for ChainOfThought. It ensures the reasoning field is always included in the output schema.
func CircuitBreakerAgentInterceptor ¶
func CircuitBreakerAgentInterceptor(cb *CircuitBreaker) core.AgentInterceptor
CircuitBreakerAgentInterceptor creates an interceptor that implements circuit breaker pattern for agents.
func CircuitBreakerModuleInterceptor ¶
func CircuitBreakerModuleInterceptor(cb *CircuitBreaker) core.ModuleInterceptor
CircuitBreakerModuleInterceptor creates an interceptor that implements circuit breaker pattern for modules.
func CircuitBreakerToolInterceptor ¶
func CircuitBreakerToolInterceptor(cb *CircuitBreaker) core.ToolInterceptor
CircuitBreakerToolInterceptor creates an interceptor that implements circuit breaker pattern for tools.
func CreateXMLInterceptorChain ¶
func CreateXMLInterceptorChain(config XMLConfig, additionalInterceptors ...core.ModuleInterceptor) []core.ModuleInterceptor
CreateXMLInterceptorChain creates a chain of XML and other interceptors.
func LoggingAgentInterceptor ¶
func LoggingAgentInterceptor() core.AgentInterceptor
LoggingAgentInterceptor creates an interceptor that logs agent execution. It logs before and after agent execution with timing information.
func LoggingModuleInterceptor ¶
func LoggingModuleInterceptor() core.ModuleInterceptor
LoggingModuleInterceptor creates an interceptor that logs module execution. It logs before and after module execution with timing information.
func LoggingToolInterceptor ¶
func LoggingToolInterceptor() core.ToolInterceptor
LoggingToolInterceptor creates an interceptor that logs tool execution. It logs before and after tool execution with timing and argument information.
func MetricsAgentInterceptor ¶
func MetricsAgentInterceptor() core.AgentInterceptor
MetricsAgentInterceptor creates an interceptor that collects performance metrics for agents.
func MetricsModuleInterceptor ¶
func MetricsModuleInterceptor() core.ModuleInterceptor
MetricsModuleInterceptor creates an interceptor that collects performance metrics for modules. It tracks execution duration, success/failure rates, and token usage.
func MetricsToolInterceptor ¶
func MetricsToolInterceptor() core.ToolInterceptor
MetricsToolInterceptor creates an interceptor that collects performance metrics for tools.
func NativeFunctionCallingInterceptor ¶
func NativeFunctionCallingInterceptor(config FunctionCallingConfig) core.ModuleInterceptor
NativeFunctionCallingInterceptor creates a module interceptor that uses native LLM function calling instead of text-based action parsing.
This interceptor transforms the ReAct pattern by: 1. Converting tools from the registry into LLM function schemas 2. Using GenerateWithFunctions instead of Generate 3. Returning structured tool calls that bypass XML/text parsing
Benefits over text-based parsing: - No hallucinated observations (LLM only returns one tool call) - Strongly typed arguments from the LLM - Provider-optimized tool selection - Eliminates parsing errors and ambiguity
Usage:
config := interceptors.FunctionCallingConfig{
ToolRegistry: registry,
IncludeFinishTool: true,
}
interceptor := interceptors.NativeFunctionCallingInterceptor(config)
react.Predict.SetInterceptors([]core.ModuleInterceptor{interceptor})
func ParseXMLAction ¶
func ParseXMLAction(actionStr string, config XMLConfig) (toolName string, arguments map[string]interface{}, err error)
ParseXMLAction parses an action string from ReAct module into tool name and arguments. This provides a centralized, robust XML parsing implementation for action strings. It handles security limits, entity escaping, and fallback logic.
func RateLimitingAgentInterceptor ¶
func RateLimitingAgentInterceptor(limit int, window time.Duration) core.AgentInterceptor
RateLimitingAgentInterceptor creates an interceptor that enforces rate limiting on agent execution. It limits the number of agent executions per time window per agent ID.
func RateLimitingToolInterceptor ¶
func RateLimitingToolInterceptor(limit int, window time.Duration) core.ToolInterceptor
RateLimitingToolInterceptor creates an interceptor that enforces rate limiting on tool execution. It limits the number of tool calls per time window per tool name.
func RetryAgentInterceptor ¶
func RetryAgentInterceptor(config RetryConfig) core.AgentInterceptor
RetryAgentInterceptor creates an interceptor that retries failed agent executions.
func RetryModuleInterceptor ¶
func RetryModuleInterceptor(config RetryConfig) core.ModuleInterceptor
RetryModuleInterceptor creates an interceptor that retries failed module executions.
func RetryToolInterceptor ¶
func RetryToolInterceptor(config RetryConfig) core.ToolInterceptor
RetryToolInterceptor creates an interceptor that retries failed tool executions.
func SanitizingAgentInterceptor ¶
func SanitizingAgentInterceptor() core.AgentInterceptor
SanitizingAgentInterceptor creates an interceptor that sanitizes agent inputs.
func SanitizingModuleInterceptor ¶
func SanitizingModuleInterceptor() core.ModuleInterceptor
SanitizingModuleInterceptor creates an interceptor that sanitizes module inputs.
func SanitizingToolInterceptor ¶
func SanitizingToolInterceptor() core.ToolInterceptor
SanitizingToolInterceptor creates an interceptor that sanitizes tool arguments.
func StructuredOutputInterceptor ¶
func StructuredOutputInterceptor(config StructuredOutputConfig) core.ModuleInterceptor
StructuredOutputInterceptor creates a module interceptor that uses native JSON output capabilities instead of text-based parsing.
This interceptor transforms the Predict module by: 1. Converting output signature fields into a JSON schema 2. Using GenerateWithJSON instead of Generate + parsing 3. Mapping the JSON response directly to output fields
Benefits over text-based parsing: - No parsing errors from malformed prefixes - Strongly typed output from the LLM - Works with any signature without custom prefix configuration - More reliable extraction of multiple output fields
Usage:
config := interceptors.DefaultStructuredOutputConfig()
interceptor := interceptors.StructuredOutputInterceptor(config)
predict.SetInterceptors([]core.ModuleInterceptor{interceptor})
Or use the convenience method on Predict:
predict := modules.NewPredict(signature).WithStructuredOutput()
func TimeoutAgentInterceptor ¶
func TimeoutAgentInterceptor(timeout time.Duration) core.AgentInterceptor
TimeoutAgentInterceptor creates an interceptor that enforces timeouts on agent execution.
func TimeoutModuleInterceptor ¶
func TimeoutModuleInterceptor(timeout time.Duration) core.ModuleInterceptor
TimeoutModuleInterceptor creates an interceptor that enforces timeouts on module execution.
func TimeoutToolInterceptor ¶
func TimeoutToolInterceptor(timeout time.Duration) core.ToolInterceptor
TimeoutToolInterceptor creates an interceptor that enforces timeouts on tool execution.
func TracingAgentInterceptor ¶
func TracingAgentInterceptor() core.AgentInterceptor
TracingAgentInterceptor creates an interceptor that adds distributed tracing to agent execution.
func TracingModuleInterceptor ¶
func TracingModuleInterceptor() core.ModuleInterceptor
TracingModuleInterceptor creates an interceptor that adds distributed tracing to module execution. It integrates with the existing span system in core.ExecutionState.
func TracingToolInterceptor ¶
func TracingToolInterceptor() core.ToolInterceptor
TracingToolInterceptor creates an interceptor that adds distributed tracing to tool execution.
func ValidationAgentInterceptor ¶
func ValidationAgentInterceptor(config ValidationConfig) core.AgentInterceptor
ValidationAgentInterceptor creates an interceptor that validates agent inputs.
func ValidationModuleInterceptor ¶
func ValidationModuleInterceptor(config ValidationConfig) core.ModuleInterceptor
ValidationModuleInterceptor creates an interceptor that validates module inputs. It checks input size, string lengths, and forbidden patterns.
func ValidationToolInterceptor ¶
func ValidationToolInterceptor(config ValidationConfig) core.ToolInterceptor
ValidationToolInterceptor creates an interceptor that validates tool arguments.
func WithAuthorizationContext ¶
func WithAuthorizationContext(ctx context.Context, authCtx *AuthorizationContext) context.Context
WithAuthorizationContext adds authorization context to the request context.
func XMLFormatModuleInterceptor ¶
func XMLFormatModuleInterceptor(config XMLConfig) core.ModuleInterceptor
XMLFormatModuleInterceptor modifies module inputs to request XML-formatted responses. This interceptor operates on the input side, injecting XML formatting instructions into the prompt to guide the LLM to produce structured XML output.
func XMLModuleInterceptor ¶
func XMLModuleInterceptor(config XMLConfig) core.ModuleInterceptor
XMLModuleInterceptor creates a combined interceptor that both formats requests and parses responses. This is a convenience function that chains the format and parse interceptors.
func XMLParseModuleInterceptor ¶
func XMLParseModuleInterceptor(config XMLConfig) core.ModuleInterceptor
XMLParseModuleInterceptor extracts structured data from XML responses. This interceptor operates on the output side, parsing XML-formatted LLM responses into structured field values according to the module's signature.
Types ¶
type AuthorizationContext ¶
type AuthorizationContext struct {
UserID string
Roles []string
Permissions []string
Scopes []string
APIKey string
}
AuthorizationContext holds authorization information.
type AuthorizationInterceptor ¶
type AuthorizationInterceptor struct {
// contains filtered or unexported fields
}
AuthorizationInterceptor creates authorization interceptors.
func NewAuthorizationInterceptor ¶
func NewAuthorizationInterceptor() *AuthorizationInterceptor
NewAuthorizationInterceptor creates a new authorization interceptor.
func (*AuthorizationInterceptor) AgentAuthorizationInterceptor ¶
func (ai *AuthorizationInterceptor) AgentAuthorizationInterceptor() core.AgentInterceptor
AgentAuthorizationInterceptor creates an interceptor that enforces authorization on agents.
func (*AuthorizationInterceptor) ModuleAuthorizationInterceptor ¶
func (ai *AuthorizationInterceptor) ModuleAuthorizationInterceptor() core.ModuleInterceptor
ModuleAuthorizationInterceptor creates an interceptor that enforces authorization on modules.
func (*AuthorizationInterceptor) SetPolicy ¶
func (ai *AuthorizationInterceptor) SetPolicy(resource string, policy AuthorizationPolicy)
SetPolicy sets an authorization policy for a specific resource.
func (*AuthorizationInterceptor) ToolAuthorizationInterceptor ¶
func (ai *AuthorizationInterceptor) ToolAuthorizationInterceptor() core.ToolInterceptor
ToolAuthorizationInterceptor creates an interceptor that enforces authorization on tools.
type AuthorizationPolicy ¶
type AuthorizationPolicy struct {
RequiredRoles []string
RequiredPermissions []string
RequiredScopes []string
RequireAuth bool
CustomRules map[string]string
AllowedModules []string
AllowedAgents []string
AllowedTools []string
}
AuthorizationPolicy defines what operations are allowed.
type Cache ¶
type Cache interface {
Get(key string) (interface{}, bool)
Set(key string, value interface{}, ttl time.Duration)
Delete(key string)
Clear()
}
Cache interface allows for different caching implementations.
type CacheEntry ¶
CacheEntry represents a cached result with expiration.
type ChainOfThoughtStructuredConfig ¶
type ChainOfThoughtStructuredConfig struct {
StructuredOutputConfig
// ReasoningFieldName is the name of the field containing the reasoning.
// Defaults to "reasoning" if empty.
ReasoningFieldName string
// IncludeReasoningInOutput determines if reasoning should be in the final output.
IncludeReasoningInOutput bool
}
ChainOfThoughtStructuredConfig extends StructuredOutputConfig for CoT-specific settings.
func DefaultChainOfThoughtStructuredConfig ¶
func DefaultChainOfThoughtStructuredConfig() ChainOfThoughtStructuredConfig
DefaultChainOfThoughtStructuredConfig returns defaults for ChainOfThought.
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker implements the circuit breaker pattern.
func NewCircuitBreaker ¶
func NewCircuitBreaker(failureThreshold int, resetTimeout time.Duration, requestThreshold int) *CircuitBreaker
NewCircuitBreaker creates a new circuit breaker.
func (*CircuitBreaker) Allow ¶
func (cb *CircuitBreaker) Allow() bool
Allow checks if a request should be allowed through the circuit breaker.
func (*CircuitBreaker) GetState ¶
func (cb *CircuitBreaker) GetState() CircuitState
GetState returns the current circuit breaker state.
func (*CircuitBreaker) RecordFailure ¶
func (cb *CircuitBreaker) RecordFailure()
RecordFailure records a failed request.
func (*CircuitBreaker) RecordSuccess ¶
func (cb *CircuitBreaker) RecordSuccess()
RecordSuccess records a successful request.
type CircuitState ¶
type CircuitState int
CircuitState represents the current state of the circuit breaker.
const ( CircuitClosed CircuitState = iota CircuitOpen CircuitHalfOpen )
type FunctionCallingConfig ¶
type FunctionCallingConfig struct {
// ToolRegistry provides the available tools for function calling.
ToolRegistry *tools.InMemoryToolRegistry
// StrictMode requires the LLM to always call a function (no free-form text).
// When false, the LLM may respond with text instead of a function call.
StrictMode bool
// IncludeFinishTool adds a special "Finish" tool that signals task completion.
// This is essential for ReAct loops to know when to stop.
IncludeFinishTool bool
// FinishToolDescription customizes the Finish tool's description.
// Defaults to a standard description if empty.
FinishToolDescription string
}
FunctionCallingConfig configures the native function calling interceptor.
func DefaultFunctionCallingConfig ¶
func DefaultFunctionCallingConfig() FunctionCallingConfig
DefaultFunctionCallingConfig returns sensible defaults for ReAct usage.
type FunctionCallingReActAdapter ¶
type FunctionCallingReActAdapter struct {
// contains filtered or unexported fields
}
FunctionCallingReActAdapter wraps the ReAct module to use native function calling. This is a higher-level helper that configures everything automatically.
func NewFunctionCallingReActAdapter ¶
func NewFunctionCallingReActAdapter(registry *tools.InMemoryToolRegistry) *FunctionCallingReActAdapter
NewFunctionCallingReActAdapter creates an adapter that enables native function calling for ReAct.
func (*FunctionCallingReActAdapter) GetInterceptor ¶
func (a *FunctionCallingReActAdapter) GetInterceptor() core.ModuleInterceptor
GetInterceptor returns the configured module interceptor.
func (*FunctionCallingReActAdapter) WithCustomFinishDescription ¶
func (a *FunctionCallingReActAdapter) WithCustomFinishDescription(description string) *FunctionCallingReActAdapter
WithCustomFinishDescription sets a custom description for the Finish tool.
func (*FunctionCallingReActAdapter) WithStrictMode ¶
func (a *FunctionCallingReActAdapter) WithStrictMode() *FunctionCallingReActAdapter
WithStrictMode enables strict mode where the LLM must always call a function.
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache implements an in-memory cache with TTL support.
func NewMemoryCache ¶
func NewMemoryCache() *MemoryCache
NewMemoryCache creates a new in-memory cache.
func (*MemoryCache) Delete ¶
func (mc *MemoryCache) Delete(key string)
Delete removes a value from the cache.
func (*MemoryCache) Get ¶
func (mc *MemoryCache) Get(key string) (interface{}, bool)
Get retrieves a value from the cache.
func (*MemoryCache) Set ¶
func (mc *MemoryCache) Set(key string, value interface{}, ttl time.Duration)
Set stores a value in the cache with TTL.
func (*MemoryCache) Stop ¶
func (mc *MemoryCache) Stop()
Stop terminates the cleanup goroutine and marks cache as stopped.
type ParsedSignature ¶
type ParsedSignature struct {
FieldMap map[string]core.OutputField
TagMap map[string]string // tag -> field name
RequiredSet map[string]bool
}
ParsedSignature caches parsing information for a signature.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter tracks request rates per key (agent, tool, etc.).
func NewRateLimiter ¶
func NewRateLimiter(limit int, window time.Duration) *RateLimiter
NewRateLimiter creates a new rate limiter with specified limit and time window.
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(key string) bool
Allow checks if a request should be allowed for the given key.
type RetryConfig ¶
type RetryConfig struct {
MaxAttempts int
Delay time.Duration
MaxBackoff time.Duration // Maximum delay between retries
Backoff float64 // Multiplier for delay between retries
}
RetryConfig holds configuration for retry operations.
type StructuredOutputAdapter ¶
type StructuredOutputAdapter struct {
// contains filtered or unexported fields
}
StructuredOutputAdapter provides a high-level interface for enabling structured output.
func NewStructuredOutputAdapter ¶
func NewStructuredOutputAdapter() *StructuredOutputAdapter
NewStructuredOutputAdapter creates an adapter for structured JSON output.
func (*StructuredOutputAdapter) GetInterceptor ¶
func (a *StructuredOutputAdapter) GetInterceptor() core.ModuleInterceptor
GetInterceptor returns the configured module interceptor.
func (*StructuredOutputAdapter) WithCustomInstructions ¶
func (a *StructuredOutputAdapter) WithCustomInstructions(instructions string) *StructuredOutputAdapter
WithCustomInstructions adds custom instructions to the prompt.
func (*StructuredOutputAdapter) WithStrictSchema ¶
func (a *StructuredOutputAdapter) WithStrictSchema() *StructuredOutputAdapter
WithStrictSchema enables strict schema validation.
func (*StructuredOutputAdapter) WithoutDescriptions ¶
func (a *StructuredOutputAdapter) WithoutDescriptions() *StructuredOutputAdapter
WithoutDescriptions disables field descriptions in the schema.
type StructuredOutputConfig ¶
type StructuredOutputConfig struct {
// StrictSchema requires all output fields to be present in the response.
// When false, missing fields are allowed and will be empty in the output.
StrictSchema bool
// IncludeDescriptions adds field descriptions to the JSON schema.
// This helps the LLM understand what each field should contain.
IncludeDescriptions bool
// CustomInstructions are prepended to the prompt to guide JSON generation.
CustomInstructions string
}
StructuredOutputConfig configures the structured output interceptor.
func DefaultStructuredOutputConfig ¶
func DefaultStructuredOutputConfig() StructuredOutputConfig
DefaultStructuredOutputConfig returns sensible defaults.
type ValidationConfig ¶
type ValidationConfig struct {
MaxInputSize int // Maximum size of input data in bytes
MaxStringLength int // Maximum length of string values
ForbiddenPatterns []string // Regex patterns that should not be present
RequiredFields []string // Fields that must be present
AllowHTML bool // Whether HTML is allowed in strings
}
ValidationConfig holds configuration for input validation.
func DefaultValidationConfig ¶
func DefaultValidationConfig() ValidationConfig
DefaultValidationConfig returns a secure default validation configuration.
type XMLConfig ¶
type XMLConfig struct {
// StrictParsing requires all output fields to be present in XML
StrictParsing bool
// FallbackToText enables text fallback for malformed XML
FallbackToText bool
// ValidateXML performs XML syntax validation before parsing
ValidateXML bool
// MaxDepth limits XML nesting depth for security (default: 10)
MaxDepth int
// MaxSize limits XML response size in bytes (default: 1MB)
MaxSize int64
// Timeout for XML parsing operations
ParseTimeout time.Duration
// CustomTags allows overriding default XML tag names for fields
CustomTags map[string]string
// IncludeTypeHints adds type information to XML instructions
IncludeTypeHints bool
// PreserveWhitespace maintains whitespace in XML content
PreserveWhitespace bool
}
XMLConfig holds configuration for XML interceptors.
func DefaultXMLConfig ¶
func DefaultXMLConfig() XMLConfig
DefaultXMLConfig returns XMLConfig with sensible defaults.
func FlexibleXMLConfig ¶
func FlexibleXMLConfig() XMLConfig
FlexibleXMLConfig creates a configuration with flexible parsing (allows fallback).
func PerformantXMLConfig ¶
func PerformantXMLConfig() XMLConfig
PerformantXMLConfig creates a configuration optimized for performance.
func SecureXMLConfig ¶
func SecureXMLConfig() XMLConfig
SecureXMLConfig creates a configuration with enhanced security settings.
func StrictXMLConfig ¶
func StrictXMLConfig() XMLConfig
StrictXMLConfig creates a configuration with strict parsing requirements.
func (XMLConfig) GetTagName ¶
GetTagName returns the XML tag name for a field.
func (XMLConfig) WithCustomTag ¶
WithCustomTag sets a custom XML tag for a field.
func (XMLConfig) WithFallback ¶
WithFallback enables/disables text fallback.
func (XMLConfig) WithMaxDepth ¶
WithMaxDepth sets maximum XML nesting depth.
func (XMLConfig) WithMaxSize ¶
WithMaxSize sets maximum XML response size.
func (XMLConfig) WithPreserveWhitespace ¶
WithPreserveWhitespace enables/disables whitespace preservation.
func (XMLConfig) WithStrictParsing ¶
WithStrictParsing sets strict parsing mode.
func (XMLConfig) WithTimeout ¶
WithTimeout sets parsing timeout.
func (XMLConfig) WithTypeHints ¶
WithTypeHints enables/disables type hints in XML instructions.
func (XMLConfig) WithValidation ¶
WithValidation enables/disables XML validation.