-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/sentinel v2 #1277
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
Feat/sentinel v2 #1277
Conversation
Design for probe-first workflow where probes are created with model_uri and model_id is optionally assigned if model exists, or resolved during deployment. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…tern Updated design to follow GuardrailDeploymentWorkflowRequest pattern: - 3-step workflow with workflow_id, step_number, trigger_workflow - Step 1: probe type selection - Step 2: policy configuration - Step 3: metadata + trigger creates probe - Returns RetrieveWorkflowDataResponse Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add schema changes for the custom probe multi-step workflow: - Add CustomProbeTypeEnum with LLM_POLICY value for probe type selection - Add CustomProbeWorkflowRequest schema with: - Workflow management fields (workflow_id, workflow_total_steps, step_number, trigger_workflow) - Step 1 fields (probe_type_option, project_id) - Step 2 fields (policy - PolicyConfig) - Step 3 fields (name, description, guard_types, modality_types) - Model validator ensuring either workflow_id OR workflow_total_steps is provided - Add CustomProbeWorkflowSteps schema for tracking accumulated workflow data - Update GuardrailCustomProbeResponse to include guard_types and modality_types fields, extracted from the rule in the extract_rule_data validator This follows the same workflow pattern as GuardrailDeploymentWorkflowRequest. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Make model_id parameter optional (UUID | None) to support deferred model lookup at deployment time - Add guard_types parameter (list[str] | None) for specifying guard types like "input" and "output" - Add modality_types parameter (list[str] | None) for specifying modality types like "text" and "image" - Pass guard_types and modality_types to GuardrailRule constructor - Add comprehensive docstring with all parameter descriptions - Add unit tests for all new parameters and edge cases This is part of the custom probe workflow implementation (Task 2). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add service configuration and methods to GuardrailCustomProbeService:
1. Add ProbeTypeConfig dataclass at module level with fields:
model_uri, scanner_type, handler, model_provider_type
2. Add PROBE_TYPE_CONFIGS dict mapping probe type options to configs:
- "llm_policy" -> model_uri="openai/gpt-oss-safeguard-20b",
scanner_type="llm", handler="gpt_safeguard",
model_provider_type="openai"
3. Add add_custom_probe_workflow method:
- Step 1: Extract probe type option, derive model_uri/scanner_type/handler
- Step 2: Store policy configuration
- Step 3: Store name, description, guard_types, modality_types
- On trigger_workflow=True at step 3: execute workflow
4. Add _execute_custom_probe_workflow private method:
- Look up model by URI -> assign model_id if found
- Get BudSentinel provider
- Build LLMConfig with handler and policy
- Create probe via CRUD method
- Update workflow status to COMPLETED or FAILED
Also includes comprehensive unit tests covering all workflow steps
and execution scenarios.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add required field validation before workflow execution (name, scanner_type, project_id, policy) - Add project validation in Step 1 to ensure project exists and is ACTIVE - Remove unused imports from add_custom_probe_workflow method - Fix conditional test assertions to use unconditional assertions - Add new tests for validation logic (invalid project, missing required data) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add POST /guardrails/custom-probe-workflow endpoint for multi-step custom probe creation workflow. The endpoint follows the existing guardrail deployment workflow pattern with proper error handling. Changes: - Import CustomProbeWorkflowRequest schema and GuardrailCustomProbeService - Add route with @require_permissions(MODEL_MANAGE) decorator - Handle ClientException (preserves status code) and generic Exception (500) - Return RetrieveWorkflowDataResponse on success Test coverage includes: - Successful workflow steps 1, 2, and 3 - ClientException handling with status code preservation - Generic exception handling returning 500 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive integration tests for the 3-step custom probe workflow: - TestFullWorkflowExecution: Tests full workflow step 1 -> 2 -> 3 with trigger_workflow=True, verifying probe creation with correct data - TestErrorScenarios: Tests invalid probe_type_option, missing required fields at step 3, BudSentinel provider not found, project not found - TestModelIdAssignment: Tests model_id is assigned when model exists, and model_id is None when model not found - TestWorkflowStatusTransitions: Tests IN_PROGRESS during steps and COMPLETED after successful trigger Tests verify: - Workflow and WorkflowStep creation - GuardrailProbe and GuardrailRule creation with correct fields - scanner_type, model_uri, model_config_json, guard_types, modality_types - Workflow status transitions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…tests - Strengthen assertion in test_bud_sentinel_provider_not_found to verify workflow status is FAILED and reason contains error message - Add test_step2_without_policy_proceeds_normally to verify step 2 works without policy (policy is optional at step 2, only required at step 3) - Update comments to clarify why ModelDataManager is patched at source module (local import inside function requires patching at the source) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove unused TestClient import and auth_headers fixture from test_custom_probe_workflow_integration.py. The ModelDataManager mock path at budapp.model_ops.crud.ModelDataManager is correct since the import happens locally inside the function. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Probes don't have a project_id column - project scoping happens at the profile level, not probe level. The parameter was carried over from the deployment workflow pattern but was never used by the CRUD method. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…efactor step processing Replace hijacked CLOUD_MODEL_ONBOARDING/GUARDRAIL_DEPLOYMENT workflow types with a dedicated CUSTOM_PROBE_CREATION enum value for custom probe workflows. Refactor step processing to accept fields at any step instead of gating by step_number, fix model_provider_type from "openai" to "cloud_model", add custom probe fields to RetrieveWorkflowStepData schema, and include Alembic migration for the new enum value. Remove outdated tests pending rewrite.
Summary of ChangesHello @lostnull, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the guardrail system by introducing a dedicated and streamlined multi-step workflow for creating custom probes. This new wizard-like process guides users through selecting probe types, configuring policies, and defining probe metadata, replacing previous ad-hoc methods. The changes also include backend refactorings to support this flexible workflow, ensuring data consistency and proper model integration, ultimately making custom guardrail creation more intuitive and robust. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a new multi-step workflow for creating custom guardrail probes, defining a new CUSTOM_PROBE_CREATION workflow type, schemas, and service logic. A critical Broken Access Control (IDOR) vulnerability was found in the retrieval and lookup of models, as the workflow's logic lacks proper scoping, potentially leading to unauthorized access or resource misuse in a multi-tenant environment. Additionally, the new workflow is being created with an incorrect type, which must be corrected for the feature to function as intended.
Summary
CUSTOM_PROBE_CREATIONworkflow type for creating custom guardrail probes via a multi-step wizard, replacing the previous approach that hijackedCLOUD_MODEL_ONBOARDING/GUARDRAIL_DEPLOYMENTtypesstep_number), enabling the frontend to send accumulated data freely - Add Alembic migration for the newcustom_probe_creationenum value inworkflow_type_enumRetrieveWorkflowStepDataschema with custom probe fields so workflow step data round-trips correctly through the retrieve endpointmodel_provider_typefrom"openai"to"cloud_model"for thegpt_safeguardprobe configChanges
budapp/commons/constants.pyCUSTOM_PROBE_CREATIONtoWorkflowTypeEnumbudapp/guardrails/services.pyGUARDRAIL_DEPLOYMENTworkflow type, remove step-number gating, add validation for step 1, fixmodel_provider_typedefaultbudapp/workflow_ops/schemas.pyRetrieveWorkflowStepDatabudapp/workflow_ops/services.pycustom_probe_creationto required data keys, populate custom probe fields in retrieve response, fixmodel_idnull checkbudapp/migrations/versions/d4e5f6a7b8c9_*custom_probe_creation+tool_creationtoworkflow_type_enumdocs/plans/guardrail-custom-probe-workflow-requirements.mdtests/(5 files deleted)API
POST /guardrails/custom-probe-workflow
Step 1 — Select probe type (creates workflow):
{ "workflow_total_steps": 3, "step_number": 1, "probe_type_option": "llm_policy" }Step 2 — Configure policy:
{ "workflow_id": "<uuid>", "step_number": 2, "policy": { "task": "...", "definitions": [...], ... } }Step 3 — Metadata + trigger:
{ "workflow_id": "<uuid>", "step_number": 3, "trigger_workflow": true, "name": "Spam Detector", "description": "...", "guard_types": ["spam"], "modality_types": ["text"] }Test plan
🤖 Generated with https://claude.ai/claude-code