Portal Community
Project: BizFirst.Ai.GuardRails.Provider.Core — Register with services.AddGuardRailsCoreGuards() or via the full-stack services.AddGuardRailsExecution().

TimeoutGuard

PropertyValue
Name"TimeoutGuard"
Version1.0.0
Supported PhasesPre Post
IsSecurityCriticalfalse → fail-open (warns when circuit broken)

How it works

Pre phase: Stores DateTime.UtcNow into context.Metadata["__timeout_start"] (only if not already set — idempotent). No blocking in Pre.

Post phase: Reads the start time, calculates elapsed milliseconds. If elapsed exceeds timeoutMs:

If __timeout_start is not in metadata (guard was not pre-initialized), the Post phase returns Success.

Configuration

{
  "name": "TimeoutGuard",
  "enabled": true,
  "config": {
    "timeoutMs": 5000,   // required; integer; minimum 100ms
    "action": "block"    // required; "block" | "warn"
  }
}

Block result metadata

{
  "elapsed_ms": 6234.5,
  "timeout_ms": 5000
}

InputValidationGuard

PropertyValue
Name"InputValidationGuard"
Version1.0.0
Supported PhasesPre
IsSecurityCriticaltrue → fail-secure

How it works

Validates context.Input against a JSON schema. If context.Input == null, returns Success (null is allowed). Otherwise:

Configuration

{
  "name": "InputValidationGuard",
  "enabled": true,
  "config": {
    "schema": {
      "type": "object",
      "required": ["userId", "amount"],
      "properties": {
        "userId":   { "type": "string" },
        "amount":   { "type": "number" },
        "currency": { "type": "string" }
      }
    },
    "strictMode": true   // optional; default false
  }
}

Block result metadata

{
  "validation_errors": [
    "Required field 'userId' is missing or null",
    "Field 'amount': expected 'number', got 'string'"
  ]
}

RateLimitingGuard

PropertyValue
Name"RateLimitingGuard"
Version1.0.0
Supported PhasesPre
IsSecurityCriticaltrue → fail-secure

How it works

Checks request count in a sliding window against rps × window (maximum allowed requests). Determines the rate limit key from scope:

ScopeKeyWhen to use
"global""global"Platform-wide cap (rare)
"tenant""tenant:{context.TenantId}"Per-tenant isolation (most common)
"user""user:{context.UserId}"Per-user quota enforcement
Production Note The current implementation uses an in-memory sliding window suitable for single-instance deployments and testing. In production multi-instance deployments, inject IRateLimitingOrchestrator from BizFirst.Platform.Operations.Guard for Redis-backed distributed rate limiting.

Configuration

{
  "name": "RateLimitingGuard",
  "enabled": true,
  "config": {
    "rps": 50,          // required; number; minimum 0.1 — requests per second
    "window": 60,       // required; integer; minimum 1 — time window in seconds
    "scope": "tenant"   // required; "global" | "tenant" | "user"
  }
}

Block result

{
  "IsAllowed": false,
  "RetryAfterSeconds": 3,
  "Metadata": {
    "scope": "tenant",
    "requests_in_window": 52,
    "limit": 50
  }
}

CircuitBreakerGuard

PropertyValue
Name"CircuitBreakerGuard"
Version1.0.0
Supported PhasesPre
IsSecurityCriticalfalse → fail-open

How it works

Monitors health of system dependencies (Redis, RateLimitService, AuditService). Maintains three states:

StateBehaviorTransition
Closed NormalAll requests allowed→ Open when failures ≥ threshold
Open BlockingRequests blocked; returns Blocked with retry-after→ HalfOpen after timeout ms
HalfOpen TestingOne test request allowed→ Closed on success; → Open on failure
Production Note The current implementation simulates health checks with Task.Delay(10–100ms) — always returns healthy. Production integration requires injecting IHealthCheckService to perform real dependency health checks.

Configuration

{
  "name": "CircuitBreakerGuard",
  "enabled": true,
  "config": {
    "threshold": 5,     // required; integer; ≥ 1 — failures before opening
    "timeout": 60000    // required; integer; ≥ 1000ms — open duration before HalfOpen
  }
}

Guard Summary Table

GuardPhaseSecurityCriticalBlocks?Modifies Output?
TimeoutGuardPrePostfalseYes (Post, action=block, timeout exceeded)No
InputValidationGuardPretrueYes (strictMode=true)No
RateLimitingGuardPretrueYes (limit exceeded)No
CircuitBreakerGuardPrefalseYes (circuit open)No