Guardrails config

From RHEcosystemAppEng/agentic-plugins · View interactive version

Guardrails config is an AI agent skill from the GitHub repository RHEcosystemAppEng/agentic-plugins. Configure TrustyAI Guardrails Orchestrator for LLM input/output content safety on OpenShift AI. Use when: - "Add guardrails to my LLM endpoint" - "Set up content safety for my model" - "Configure PII detection on my inference endpoint" - "Block prompt injection attacks" - "I need a guarded endpoint

How to use this skill

Skill file

/guardrails-config Skill

Prerequisites

Required MCP Server: openshift (OpenShift MCP Server)

Required MCP Tools (from openshift):

Preferred MCP Server: rhoai (RHOAI MCP Server) — used when available, automatic OpenShift fallback on failure

Preferred MCP Tools (from rhoai):

Optional MCP Server: ai-observability (AI Observability MCP)

Optional MCP Tools (from ai-observability):

Common prerequisites (KUBECONFIG, OpenShift+RHOAI cluster, KServe, verification protocol): See skill-conventions.md.

Fallback templates: See openshift-fallback-templates.md for OpenShift YAML templates used when RHOAI tools are unavailable.

Additional cluster requirements:

When to Use This Skill

Use this skill when you need to:

Do NOT use this skill when:

Workflow

Step 1: Verify GuardrailsOrchestrator CRD

MCP Tool: resources_list (from openshift)

Parameters:

Check for guardrailsorchestrators.trustyai.opendatahub.io CRD. This is a hard prerequisite — nothing in this skill works without it.

Error Handling:

Step 2: Gather Guardrails Requirements

Ask the user for:

If user is unsure about target model, use list_inference_services (from rhoai) to present available models.

MCP Tool: list_inference_services (from rhoai)

Parameters:

If rhoai unavailable or returns error: Use resources_list (from openshift) with apiVersion: serving.kserve.io/v1beta1, kind: InferenceService, namespace: [namespace].

Verify the selected InferenceService is Ready:

MCP Tool: get_inference_service (from rhoai)

Parameters:

If rhoai unavailable or returns error: Use resources_get (from openshift) with apiVersion: serving.kserve.io/v1beta1, kind: InferenceService, name: [name], namespace: [namespace]. Extract status from .status.conditions.

If not Ready: Warn user and offer options: (1) Proceed anyway, (2) Invoke /debug-inference, (3) Abort. WAIT for user decision.

MCP Tool: get_model_endpoint (from rhoai)

Parameters:

If rhoai unavailable or returns error: Extract endpoint from .status.url of the InferenceService obtained via resources_get (from openshift).

Store the endpoint URL for orchestrator routing. Present configuration summary for confirmation. WAIT for user to confirm or modify.

Step 3: Configure Detectors

Document Consultation (read before configuring detectors):

  1. Action: Read guardrails-detectors-reference.md using the Read tool to understand detector types, recommended models, and configuration structure
  2. Output to user: "I consulted guardrails-detectors-reference.md to understand available detector configurations."

For each selected detector type:

Step 3a: Content Safety Detector (if selected)

Recommended model: ibm-granite/granite-guardian-3.1-2b (1 GPU, ~8Gi memory) per guardrails-detectors-reference.md.

Check if a compatible detector model is already deployed using list_inference_services (from rhoai). If one exists, offer to reuse it. WAIT for user decision.

If rhoai unavailable or returns error: Use resources_list (from openshift) with apiVersion: serving.kserve.io/v1beta1, kind: InferenceService, namespace: [namespace] to check for existing detector models. To list available runtimes when list_serving_runtimes is unavailable: Use resources_list (from openshift) with apiVersion: serving.kserve.io/v1alpha1, kind: ServingRuntime, namespace: [namespace].

If deploying a new detector:

MCP Tool: deploy_model (from rhoai)

Parameters:

If rhoai unavailable or returns error: Use resources_create_or_update (from openshift) to create the detector InferenceService CR directly with apiVersion: serving.kserve.io/v1beta1, kind: InferenceService.

Ask: "Deploy the content safety detector model? This creates an additional InferenceService. (yes/no/use-existing)"

WAIT for explicit confirmation. Monitor deployment until Ready.

Error Handling:

Step 3b: PII Detection (if selected)

Uses built-in regex-based detectors (no model deployment needed). Generate appropriate regex patterns. Present patterns to user for review. WAIT for user decision.

Step 3c: Prompt Injection Detector (if selected)

For model-based detection: reuse the granite-guardian model from Step 3a (covers prompt injection). For keyword-based detection: configure patterns. WAIT for user decision.

Step 3d: Custom Regex Detector (if requested)

Collect pattern name, regex, scope, and action from user.

Step 4: Create Detector ConfigMap

Construct ConfigMap using the orchestrator config structure from guardrails-detectors-reference.md. Populate with detector configs from Step 3 and target model endpoint from Step 1.

MCP Tool: resources_create_or_update (from openshift)

Parameters:

ConfigMap name: guardrails-config-[isvc-name]. Labels: app.kubernetes.io/part-of: trustyai-guardrails, trustyai.opendatahub.io/target-model: [isvc-name].

Display the full ConfigMap to user. Ask: "Proceed with this guardrails configuration? (yes/no/modify)"

WAIT for explicit confirmation.

Step 5: Deploy GuardrailsOrchestrator CR

Construct GuardrailsOrchestrator manifest using CRD spec from guardrails-detectors-reference.md. Key values: name=guardrails-[isvc-name], orchestratorConfig=guardrails-config-[isvc-name], enableBuiltInDetectors=true, enableGuardrailsGateway=true.

MCP Tool: resources_create_or_update (from openshift)

Parameters:

Display manifest to user. Ask: "Deploy this GuardrailsOrchestrator? (yes/no/modify)"

WAIT for explicit confirmation.

Error Handling:

Step 6: Verify Orchestrator Deployment

MCP Tool: pods_list (from openshift)

Parameters:

Verify orchestrator pod is Running. Poll every 15 seconds for up to 5 minutes.

On failure: Use pods_log and events_list (from openshift) to diagnose. Present options: (1) View full logs, (2) Check events, (3) Delete and recreate, (4) Abort. WAIT for user decision. NEVER auto-delete GuardrailsOrchestrator.

Get guarded endpoint: Use resources_get (from openshift) to read the GuardrailsOrchestrator CR status (apiVersion: trustyai.opendatahub.io/v1alpha1, kind: GuardrailsOrchestrator) and extract the guarded endpoint URL.

Step 7: Validate Guarded Endpoint

First, verify the original model still responds correctly:

MCP Tool: test_model_endpoint (from rhoai)

Parameters:

If rhoai unavailable or returns error: Note that test_model_endpoint only checks reachability, not actual inference. For a real inference test, use an in-cluster curl command: curl -X POST [endpoint]/v1/completions -H 'Content-Type: application/json' -d '{"model":"[model]","prompt":"Hello","max_tokens":10}'

Then test the guarded endpoint directly. The guarded endpoint is a different URL from the original — obtain it from the GuardrailsOrchestrator CR status (Step 6). If the guarded endpoint is only available cluster-internally, set up port-forwarding to the orchestrator service first:

oc port-forward svc/guardrails-[isvc-name] 8080:8080 -n [namespace]

Run a safe request against the guarded endpoint to confirm it proxies correctly, then run an unsafe request (e.g., prompt injection attempt) to verify the detectors are active. Present both results to the user with pass/fail for each test.

Step 8: Summary and Next Steps

Present summary showing: guarded vs original endpoint URLs, active detectors table (name, type, scope, policy), usage instructions (applications should use guarded endpoint), and next steps (/model-monitor, /ai-observability).

Common Issues

For common issues (GPU scheduling, OOMKilled, image pull errors, RBAC), see common-issues.md.

Issue 1: Detector Model Deployment Fails

Error: Content safety or prompt injection detector model InferenceService fails to start

Cause: Insufficient resources (GPU/memory) for the detector model, or runtime compatibility issues.

Solution:

  1. Check detector model resource requirements -- classifier models are typically 2B parameters
  2. Verify GPU availability for the detector model
  3. Consider CPU-only deployment for smaller detector models
  4. Use /debug-inference to troubleshoot the detector InferenceService

Issue 2: Guarded Endpoint Returns 502/503

Error: Requests to the guarded endpoint return 502 Bad Gateway or 503 Service Unavailable

Cause: The orchestrator cannot reach the underlying model endpoint, or the detector service is down.

Solution:

  1. Verify the original model endpoint is accessible: test_model_endpoint from rhoai
  2. Check orchestrator pod logs for connection errors: pods_log
  3. Verify the ConfigMap orchestrator.target_model.endpoint URL is correct
  4. Check detector model pods are running if using model-based detectors
  5. Check network policies that might block pod-to-pod communication

Issue 3: GuardrailsOrchestrator RBAC Denied

Error: Cannot create guardrailsorchestrators resource — 403 Forbidden

Cause: The user lacks RBAC for the GuardrailsOrchestrator CRD, which is typically cluster-admin only.

Solution: Provide the user with the complete GuardrailsOrchestrator CR YAML and instruct them to ask a cluster administrator to apply it. The detectors ConfigMap (which only requires namespace edit role) can still be created by the skill.

Issue 4: High Latency or False Positives

Error: Guarded endpoint is significantly slower than direct endpoint, or legitimate requests are blocked

Cause: Too many model-based detectors add latency; overly aggressive thresholds or broad regex patterns cause false positives.

Solution:

  1. Switch policy from "block" to "warn" temporarily to audit false positives
  2. Use regex-based detectors instead of model-based where possible (lower latency)
  3. Reduce detector count or switch from "input+output" to single scope
  4. Review orchestrator logs to identify which detector triggered
  5. Re-run /guardrails-config with modified configuration

Dependencies

MCP Tools

See Prerequisites for the complete list of required and optional MCP tools.

Related Skills

Reference Documentation

Critical: Human-in-the-Loop Requirements

See skill-conventions.md for general HITL and security conventions.

Skill-specific checkpoints:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.