Skip to content

Conversation

@devangjhabakh
Copy link

Summary

Brief description of what this PR does and why.

Fixes #(issue)

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

How has this been tested? What should reviewers focus on?

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

@vercel
Copy link

vercel bot commented Oct 10, 2025

Someone is attempting to deploy a commit to the Sim Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 guardrails block with conditional UI for different validation types
  • API route at /api/guardrails/validate that 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-list component 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.ts line 145. Consider reviewing timeout handling in apps/sim/lib/guardrails/validate_pii.ts line 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
Loading

23 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1 waleedlatif1 changed the title Adding guardrails block feat(guardrails): added guardrails block & docs Oct 11, 2025
@waleedlatif1 waleedlatif1 changed the base branch from main to staging October 11, 2025 19:45
@waleedlatif1
Copy link
Collaborator

updated version in #1605

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants