-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(guardrails): added guardrails block & docs #1589
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(guardrails): added guardrails block & docs #1589
Conversation
|
Someone is attempting to deploy a commit to the Sim Team on Vercel. A member of the Team first needs to authorize it. |
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.
Greptile Overview
Summary
This PR adds a comprehensive guardrails block that validates content using four different validation types: JSON validation, regex pattern matching, hallucination detection via RAG+LLM, and PII detection using Microsoft Presidio.
Key Changes:
- New
guardrailsblock with conditional UI for different validation types - API route at
/api/guardrails/validatethat routes to appropriate validators - JSON and regex validators implemented in TypeScript
- Hallucination detector queries knowledge base and uses LLM to score content confidence (0-10 scale)
- PII detector wraps Microsoft Presidio Python library via subprocess, supporting both block and mask modes
- Docker integration adds Python 3, pip, and runs setup script to install Presidio dependencies
- New
grouped-checkbox-listcomponent for selecting PII entity types - Comprehensive documentation in MDX format
Issues Found:
- Typo in route.ts line 145: "strfing" should be "string" (comment syntax)
- Timeout handling in validate_pii.ts resolves instead of rejecting, making timeouts indistinguishable from normal failures (comment logic)
Confidence Score: 4/5
- This PR is safe to merge after fixing the typo - the logic issue is minor
- Score of 4 reflects well-structured implementation with proper error handling, comprehensive documentation, and Docker integration. Two minor issues found: a typo that needs fixing (syntax error) and a timeout handling inconsistency (logic issue). The core functionality is solid with good separation of concerns between TypeScript and Python components.
- Fix the typo in
apps/sim/app/api/guardrails/validate/route.tsline 145. Consider reviewing timeout handling inapps/sim/lib/guardrails/validate_pii.tsline 83 for better error propagation.
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/blocks/blocks/guardrails.ts | 4/5 | Adds comprehensive guardrails block configuration with 4 validation types (JSON, regex, hallucination, PII). Includes proper conditional field display and extensive PII entity types list. |
| apps/sim/app/api/guardrails/validate/route.ts | 3/5 | New API route for guardrails validation. Contains minor typo on line 145 ("strfing"). Properly handles validation types and error cases. |
| apps/sim/lib/guardrails/validate_pii.ts | 3/5 | TypeScript wrapper for Python PII detection. Timeout handling resolves instead of rejecting (line 83), making error types indistinguishable. Otherwise solid implementation. |
| apps/sim/lib/guardrails/validate_hallucination.ts | 4/5 | RAG-based hallucination detection using LLM scoring. Queries knowledge base and uses LLM to score content confidence (0-10 scale). Solid implementation with proper error handling. |
| docker/app.Dockerfile | 4/5 | Adds Python 3 and pip to runner stage, copies guardrails files, runs setup script to install Presidio dependencies. Proper integration with existing Docker build. |
Sequence Diagram
sequenceDiagram
participant User
participant GuardrailsBlock
participant ValidateAPI
participant JSONValidator
participant RegexValidator
participant HallucinationValidator
participant KnowledgeBase
participant LLM
participant PIIValidator
participant PresidioPython
User->>GuardrailsBlock: Configure validation type
User->>GuardrailsBlock: Execute workflow
GuardrailsBlock->>ValidateAPI: POST /api/guardrails/validate
alt JSON Validation
ValidateAPI->>JSONValidator: validateJson(input)
JSONValidator->>JSONValidator: JSON.parse(input)
JSONValidator-->>ValidateAPI: {passed, error?}
else Regex Validation
ValidateAPI->>RegexValidator: validateRegex(input, pattern)
RegexValidator->>RegexValidator: new RegExp(pattern).test(input)
RegexValidator-->>ValidateAPI: {passed, error?}
else Hallucination Check
ValidateAPI->>HallucinationValidator: validateHallucination(params)
HallucinationValidator->>KnowledgeBase: Query for relevant chunks
KnowledgeBase-->>HallucinationValidator: Return context chunks
HallucinationValidator->>LLM: Score confidence (0-10)
LLM-->>HallucinationValidator: {score, reasoning}
HallucinationValidator->>HallucinationValidator: Check score >= threshold
HallucinationValidator-->>ValidateAPI: {passed, score, reasoning}
else PII Detection
ValidateAPI->>PIIValidator: validatePII(params)
PIIValidator->>PresidioPython: spawn python process
PIIValidator->>PresidioPython: Send input via stdin
PresidioPython->>PresidioPython: Presidio analyze/anonymize
PresidioPython-->>PIIValidator: JSON result via stdout
PIIValidator-->>ValidateAPI: {passed, detectedEntities, maskedText?}
end
ValidateAPI-->>GuardrailsBlock: Validation result
GuardrailsBlock-->>User: Display result & continue workflow
23 files reviewed, 2 comments
|
updated version in #1605 |
Summary
Brief description of what this PR does and why.
Fixes #(issue)
Type of Change
Testing
How has this been tested? What should reviewers focus on?
Checklist
Screenshots/Videos