Skip to content

feat: Add deterministic guardrails filtering action#364

Merged
apetraru-uipath merged 1 commit intomainfrom
feat/AL-255_guardrails_filter_action
Dec 22, 2025
Merged

feat: Add deterministic guardrails filtering action#364
apetraru-uipath merged 1 commit intomainfrom
feat/AL-255_guardrails_filter_action

Conversation

@apetraru-uipath
Copy link
Copy Markdown
Contributor

@apetraru-uipath apetraru-uipath commented Dec 18, 2025

Filter Action Implementation - PR Summary

Overview

Implements filter action for deterministic tool guardrails, allowing selective removal of input/output fields based on guardrail rules.

Key Features

✅ Execution Stage Awareness

  • PRE_EXECUTION: Filters input fields only
  • POST_EXECUTION: Filters output fields only
  • Guardrails trigger based on rules, actions apply based on stage

✅ Python Dict String Handling

  • Added ast.literal_eval() fallback for tool outputs stored as dict string representations
  • Handles JSON strings, native dicts, and Python literal strings

✅ Type Safety & Code Quality

  • Fixed mypy type errors with proper BaseGuardrail annotations
  • Resolved test file naming conflicts (test_utils.pytest_guardrails_utils.py)
  • Replaced mock objects with proper GuardrailSelector types

Implementation Details

Modified Files

  • filter_action.py - Core filtering logic with stage-aware field filtering
  • utils.py - Enhanced data extraction with dict literal parsing
  • guardrails_factory.py - Type safety improvements
  • guardrails_subgraph.py - Bug fix for POST_EXECUTION node routing

Test Coverage

  • 17 comprehensive tests (consolidated from 20, -15% reduction)
  • 165 total guardrails tests passing
  • All edge cases covered: empty fields, missing data, non-JSON content, multiple fields

Validation

Tested against 7 agent configurations covering:

  • Always rules (PRE/POST)
  • Conditional rules (word matching)
  • Field selectors (specific/all)
  • Same-field filtering
  • Multiple field filtering

@apetraru-uipath apetraru-uipath force-pushed the feat/AL-255_guardrails_filter_action branch 7 times, most recently from 9466d59 to b3a5dea Compare December 18, 2025 21:13
Comment thread tests/agent/guardrails/test_guardrails_utils.py
Comment thread tests/agent/guardrails/test_utils.py Outdated
Comment thread tests/agent/guardrails/test_utils.py Outdated
Comment thread src/uipath_langchain/agent/guardrails/utils.py Outdated
Comment thread src/uipath_langchain/agent/guardrails/guardrails_factory.py
Comment thread tests/agent/guardrails/test_guardrails_factory.py Outdated
Comment thread tests/agent/guardrails/test_guardrails_factory.py Outdated
Comment thread src/uipath_langchain/agent/guardrails/actions/filter_action.py Outdated
@apetraru-uipath apetraru-uipath force-pushed the feat/AL-255_guardrails_filter_action branch from b3a5dea to 8d2584d Compare December 19, 2025 14:25
Comment thread src/uipath_langchain/agent/guardrails/actions/filter_action.py Outdated
Comment thread src/uipath_langchain/agent/guardrails/actions/filter_action.py Outdated
Comment thread src/uipath_langchain/agent/guardrails/actions/filter_action.py Outdated
Comment thread tests/agent/guardrails/actions/test_filter_action.py Outdated
Comment thread tests/agent/guardrails/actions/test_filter_action.py Outdated
Comment thread tests/agent/guardrails/actions/test_filter_action.py Outdated
@apetraru-uipath apetraru-uipath force-pushed the feat/AL-255_guardrails_filter_action branch 5 times, most recently from edc660b to c867d87 Compare December 19, 2025 19:05
Comment thread tests/agent/guardrails/test_guardrails_utils.py Outdated
Comment thread src/uipath_langchain/agent/guardrails/guardrails_factory.py Outdated
Comment thread tests/agent/guardrails/actions/test_filter_action.py Outdated
Comment thread tests/agent/guardrails/actions/test_filter_action.py Outdated
Copy link
Copy Markdown
Contributor

@valentinabojan valentinabojan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please bump the package version (and update it in uipath-agents).
Also, please update the PR description to reflect the latest state of the changes.

@apetraru-uipath apetraru-uipath force-pushed the feat/AL-255_guardrails_filter_action branch 2 times, most recently from a369899 to 25b108d Compare December 22, 2025 11:18
if not msgs:
return {}

# Find the AIMessage with tool calls (might not be the last message at POST_EXECUTION)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have logic for POST execution for input filtering?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was an obsolete comment. I update it!

@apetraru-uipath apetraru-uipath force-pushed the feat/AL-255_guardrails_filter_action branch 2 times, most recently from 435583a to 44daf41 Compare December 22, 2025 13:27
@apetraru-uipath apetraru-uipath force-pushed the feat/AL-255_guardrails_filter_action branch from 44daf41 to 6e452d2 Compare December 22, 2025 13:58
@apetraru-uipath apetraru-uipath merged commit 731d81b into main Dec 22, 2025
39 checks passed
@apetraru-uipath apetraru-uipath deleted the feat/AL-255_guardrails_filter_action branch December 22, 2025 14:06
mjnovice pushed a commit that referenced this pull request Mar 31, 2026
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