You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For structuring the agent guardrails and sanitizer pipeline in server/api/views/assistant/sanitizer.py:
Layered Sanitization Pipeline:
Stage 1 (O(1) Structural Injection Pre-filter):
Strip instruction-override tags and block common prompt-injection syntax before context assembly:
importrefromtypingimportTupleINJECTION_PATTERNS= [
r"(?i)\bignore\s+(all\s+)?(previous|prior)\s+instructions\b",
r"(?i)\bsystem\s*:\s*override\b",
r"(?i)\byou\s+are\s+now\s+in\s+developer\s+mode\b"
]
defprefilter_user_input(text: str) ->Tuple[bool, str]:
forpatterninINJECTION_PATTERNS:
ifre.search(pattern, text):
returnFalse, "Input flagged by injection guardrail."returnTrue, text
Stage 2 (PII Redaction):
Replace emails, phone numbers, and identifying tokens with deterministic placeholders ([REDACTED_EMAIL], [REDACTED_PHONE]) before storing or sending to the LLM.
Stage 3 (Async Moderation Gate):
Evaluate openai.moderations.create in parallel with vector retrieval, aborting immediately if safety thresholds are violated.
Pre-flight Tool Execution Validation:
Validate tool invocation arguments against strict Pydantic models before executing backend database queries or calculations.
Activity
mahirhir commentedon Aug 27, 2026
For structuring the agent guardrails and sanitizer pipeline in
server/api/views/assistant/sanitizer.py:Layered Sanitization Pipeline:
Strip instruction-override tags and block common prompt-injection syntax before context assembly:
Replace emails, phone numbers, and identifying tokens with deterministic placeholders (
[REDACTED_EMAIL],[REDACTED_PHONE]) before storing or sending to the LLM.Evaluate
openai.moderations.createin parallel with vector retrieval, aborting immediately if safety thresholds are violated.Pre-flight Tool Execution Validation:
We use this layered data-sanitization and schema-enforced tool receipt pattern in https://github.com/TraceFold/tracefold (architecture in docs/TRACEFOLD_TR.md §4.1) for production agent safety.