-
Notifications
You must be signed in to change notification settings - Fork 101
LCORE-3394: Granite Guardian Shield Docs #2637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -248,7 +248,7 @@ Global service configuration. | |
| | rag | | Unified RAG configuration: BYOK stores, OKP provider, and retrieval strategies (inline and tool-based). | | ||
| | skills | | Agent skills configuration. Specifies paths to skill directories. | | ||
| | saved_prompts | | Configuration for saved prompts feature limits including maximum prompts per user, display name length, and content length. | | ||
| | shields | array | List of pydantic-ai-lightspeed agent guardrail shields (question validity and PII redaction). Each entry has a unique 'name', a 'provider_id' ('question_validity' or 'redaction'), and a type-specific 'config'. | | ||
| | shields | array | List of LCS guardrail shields (question validity, PII redaction, and Granite Guardian). Each entry has a unique 'name', a 'provider_id' ('question_validity', 'redaction', or 'granite_guardian'), and a type-specific 'config'. See [shields_guide.md](shields_guide.md). | | ||
|
|
||
|
|
||
| ## ConversationHistoryConfiguration | ||
|
|
@@ -360,6 +360,37 @@ Inference configuration. | |
| | max_tool_calls | integer | Server-side default for the maximum number of tool calls allowed in a single response. Prevents small models from exhausting the context window with repeated tool calls. Per-request values take precedence over this default. Set to None to disable the limit. | | ||
|
|
||
|
|
||
| ## GraniteGuardianConfig | ||
|
|
||
|
|
||
| Configuration for the Granite Guardian moderation guardrail. | ||
|
|
||
|
|
||
| | Field | Type | Description | | ||
| |-------------|---------|-------------| | ||
| | url | string | Base URL of the OpenAI-compatible Granite Guardian API. | | ||
| | model_id | string | Model name sent to the inference server (default `ibm-granite/granite-guardian-4.1-8b`); override when the server registers the model under a different name. | | ||
| | api_key | string | API key for the inference endpoint (optional). | | ||
| | max_retries | integer | Maximum number of retries for transient errors (0–5, default 2). | | ||
| | timeout | integer | Request timeout in seconds (5–300, default 30). | | ||
| | verify_ssl | boolean or string | TLS verification: `true`, `false`, or path to a CA bundle (default `true`). | | ||
| | batch_size | integer | Number of risk checks to run in parallel per batch (1–10, default 3). | | ||
|
Comment on lines
+372
to
+377
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win Remove unsupported Granite Guardian fields from the documentation. 🤖 Prompt for AI Agents |
||
| | risks | array | List of [RiskDefinition](#riskdefinition) entries to evaluate. | | ||
|
|
||
|
|
||
| ## GraniteGuardianShieldConfiguration | ||
|
|
||
|
|
||
| Configuration for a named Granite Guardian guardrail shield. | ||
|
|
||
|
|
||
| | Field | Type | Description | | ||
| |-------------|--------|-------------| | ||
| | name | string | Unique, user-facing name identifying this shield instance. | | ||
| | provider_id | string | Must be `granite_guardian`. | | ||
| | config | | [GraniteGuardianConfig](#graniteguardianconfig) for this shield. | | ||
|
|
||
|
|
||
| ## JsonPathOperator | ||
|
|
||
|
|
||
|
|
@@ -792,6 +823,23 @@ Attributes: | |
| | config | | Redaction-specific configuration for this shield. | | ||
|
|
||
|
|
||
| ## RiskDefinition | ||
|
|
||
|
|
||
| Definition for a custom risk category evaluated by Granite Guardian. | ||
|
|
||
|
|
||
| | Field | Type | Description | | ||
| |-------------------|---------|-------------| | ||
| | name | string | Unique identifier for this risk (for example `roleplay-jailbreak`). | | ||
| | description | string | Risk definition text passed to Granite Guardian as `custom_criteria`. | | ||
| | threshold | number | Score threshold for flagging, 0.0–1.0 (default 0.65; lower = more sensitive). | | ||
| | enabled | boolean | Whether to run this check (default `true`). | | ||
| | enable_thinking | boolean | Internal — set via `ModerationConfig.thinking_enabled`, not directly. | | ||
| | points | array | Where to evaluate: `input`, `output`, and/or `tool` (at least one). | | ||
| | violation_message | string | Message returned when this risk is violated. | | ||
|
|
||
|
|
||
| ## RerankerConfiguration | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ request overrides work. | |
| - [Supported shield types](#supported-shield-types) | ||
| - [question_validity](#question_validity) | ||
| - [redaction](#redaction) | ||
| - [granite_guardian](#granite_guardian) | ||
| - [How shields apply at runtime](#how-shields-apply-at-runtime) | ||
| - [Agent-based endpoints](#agent-based-endpoints) | ||
| - [Responses-based endpoints](#responses-based-endpoints) | ||
|
|
@@ -38,7 +39,7 @@ configuration. Each entry has: | |
| | Field | Meaning | | ||
| |-------|---------| | ||
| | `name` | Unique shield name used in `/v1/shields` and in `shield_ids` overrides | | ||
| | `provider_id` | Shield type discriminator (`question_validity` or `redaction`) | | ||
| | `provider_id` | Shield type discriminator (`question_validity`, `redaction`, or `granite_guardian`) | | ||
| | `config` | Type-specific settings | | ||
|
|
||
| Names must be unique across the `shields` list. | ||
|
|
@@ -75,6 +76,7 @@ for a complete example. | |
| |---------------|---------|---------------------| | ||
| | `question_validity` | Classify whether the user question is in-topic; reject off-topic input with a fixed reply | Agent capability on agent-based endpoints; also considered by direct-run input moderation | | ||
| | `redaction` | Regex-based PII / sensitive-data redaction of model messages | Agent capability on agent-based endpoints | | ||
| | `granite_guardian` | IBM Granite Guardian model screening for custom safety risks at input, output, and tool points | Planned: same endpoints as other shields; **not yet implemented at runtime** — see [Granite Guardian Shield](granite_guardian_shield.md) | | ||
|
|
||
| ## question_validity | ||
|
|
||
|
|
@@ -93,6 +95,28 @@ for a complete example. | |
|
|
||
| Invalid regex patterns are rejected at configuration load time. | ||
|
|
||
| ## granite_guardian | ||
|
|
||
| IBM Granite Guardian screening with configurable risk definitions, thresholds, | ||
| and guardrail points (`input`, `output`, `tool`). Requires a Granite Guardian | ||
| model behind an OpenAI-compatible API. | ||
|
|
||
| | Config field | Required | Description | | ||
| |--------------|----------|-------------| | ||
| | `url` | Yes | Base URL of the OpenAI-compatible Granite Guardian API | | ||
| | `model_id` | No (default `ibm-granite/granite-guardian-4.1-8b`) | Model name sent to the inference server; override when the server registers the model under a different name (for example an Ollama tag) | | ||
| | `api_key` | No | API key for the inference endpoint | | ||
| | `timeout` | No (default `30`) | Request timeout in seconds (5-300) | | ||
| | `max_retries` | No (default `2`) | Retry count for transient errors (0-5) | | ||
| | `verify_ssl` | No (default `true`) | TLS verification: `true`, `false`, or a path to a CA bundle | | ||
| | `batch_size` | No (default `3`) | Number of risk checks to run in parallel per batch (1-10) | | ||
| | `risks` | Yes | Non-empty list of risk definitions: `{name, description, points, violation_message, threshold?, enabled?}` | | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| > [!NOTE] | ||
| > Configuration is validated at startup, but the runtime capability is not yet | ||
| > wired. See the dedicated [Granite Guardian Shield guide](granite_guardian_shield.md) | ||
| > for prerequisites, risk-definition guidance, examples, and implementation status. | ||
|
Comment on lines
+115
to
+118
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -C 6 '\b(build_shield|_shield_capability)\s*\(' src tests 2>/dev/null
rg -n -C 6 'Granite Guardian capability not implemented|GraniteGuardianConfig' src tests 2>/dev/nullRepository: lightspeed-core/lightspeed-stack Length of output: 11601 🤖 get_repo_knowledge executed:
Length of output: 17905 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- shield builders and callers ---'
sed -n '90,220p' src/utils/shields.py
sed -n '150,220p' src/utils/pydantic_ai_helpers.py
rg -n -C 8 '_agent_capabilities|_shield_capability|build_shield|shields.*startup|startup.*shields|pydantic_ai' src tests
printf '%s\n' '--- referenced docs and example ---'
sed -n '95,125p' docs/user_doc/shields_guide.md
sed -n '25,48p' examples/lightspeed-stack-shields.yamlRepository: lightspeed-core/lightspeed-stack Length of output: 50391 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '100,220p' src/utils/shields.py
sed -n '150,220p' src/utils/pydantic_ai_helpers.py
rg -n -C 8 '_agent_capabilities|_shield_capability|build_shield|shields' src | head -240
sed -n '95,125p' docs/user_doc/shields_guide.md
sed -n '25,48p' examples/lightspeed-stack-shields.yamlRepository: lightspeed-core/lightspeed-stack Length of output: 25334 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- pydantic helper callers ---'
rg -n -C 12 '_agent_capabilities|_shield_capability' src
printf '%s\n' '--- shield function and direct callers ---'
sed -n '100,180p' src/utils/shields.py
rg -n -C 10 'run_shields|build_shield\(' src
printf '%s\n' '--- docs and example ---'
sed -n '100,122p' docs/user_doc/shields_guide.md
sed -n '32,44p' examples/lightspeed-stack-shields.yamlRepository: lightspeed-core/lightspeed-stack Length of output: 16098 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- build_agent callers and lifecycle ---'
rg -n -C 10 '\bbuild_agent\s*\(' src --glob '*.py'
printf '%s\n' '--- build_agent definition ---'
sed -n '245,305p' src/utils/pydantic_ai_helpers.py
printf '%s\n' '--- configuration loading validation ---'
rg -n -C 8 'load.*config|configuration\.load|validate.*config|Config.*startup|startup' src/configuration.py src/app src/main.py 2>/dev/null | head -220Repository: lightspeed-core/lightspeed-stack Length of output: 21024 Correct the Granite Guardian runtime-status description
📍 Affects 2 files
🤖 Prompt for AI Agents |
||
|
|
||
| # How shields apply at runtime | ||
|
|
||
| The same shield logic (`question_validity` and `redaction`) is used on both | ||
|
|
@@ -132,7 +156,7 @@ Each catalog entry has this shape: | |
| | Field | Description | | ||
| |-------|-------------| | ||
| | `name` | Configured shield name | | ||
| | `provider_id` | `question_validity` or `redaction` | | ||
| | `provider_id` | `question_validity`, `redaction`, or `granite_guardian` | | ||
| | `type` | Always `"shield"` | | ||
| | `config` | Type-specific shield configuration | | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: lightspeed-core/lightspeed-stack
Length of output: 25615
🤖 get_repo_knowledge executed:
get_repo_knowledge lightspeed-core/lightspeed-stack /tmp/coderabbit-repo-knowledge/lightspeed-core-lightspeed-stack-d57c5c34/architecture /tmp/coderabbit-repo-knowledge/lightspeed-core-lightspeed-stack-d57c5c34/learningsLength of output: 47419
🏁 Script executed:
Repository: lightspeed-core/lightspeed-stack
Length of output: 5751
🏁 Script executed:
Repository: lightspeed-core/lightspeed-stack
Length of output: 50391
Document
max_retriesas1–5in both tables.GraniteGuardianConfig.max_retriescombinesPositiveIntwithle=5; Pydantic therefore rejects0during configuration validation. Updatedocs/user_doc/config.mdanddocs/user_doc/shields_guide.md.📍 Affects 2 files
docs/user_doc/config.md#L373-L373(this comment)docs/user_doc/shields_guide.md#L109-L109🤖 Prompt for AI Agents