Skip to content

feat: generate HITL form schema dynamically via LLM for guardrail escalations#919

Draft
dushyant-uipath wants to merge 1 commit into
mainfrom
feat/guardrail-dynamic-hitl-schema
Draft

feat: generate HITL form schema dynamically via LLM for guardrail escalations#919
dushyant-uipath wants to merge 1 commit into
mainfrom
feat/guardrail-dynamic-hitl-schema

Conversation

@dushyant-uipath

Copy link
Copy Markdown
Contributor

Summary

  • EscalateAction (agent graph path) now generates a HitlSchema at escalation time using model.with_structured_output(HitlSchema).ainvoke(state.messages + [prompt])
  • The LLM uses the full conversation context — system prompt, user request, offending tool call — to produce a reviewer form that is specific to the violation
  • Generated schema travels inline with create_quickform_async; no pre-deployed Action App required
  • create_agent injects the model into any EscalateAction automatically — no API change for callers
  • Falls back to the existing static Action App path when no model is present (backward compatible)
  • Middleware EscalateAction is unchanged

Depends on

UiPath/uipath-python#1737 must be merged and published before this PR can be fully functional (uipath-platform version constraint will be bumped after that lands).

Design doc

https://uipath.atlassian.net/wiki/spaces/BPA/pages/90813301792/Dynamic+Schemas+for+Agent+Guardrail+Escalations

Test plan

  • Existing guardrail tests: uv run pytest tests/guardrails/ tests/agent/guardrails/ — 458 passing
  • Manual E2E: write an agent with a guardrail that always fires, run it, verify the Action Center task is a QuickForm whose fields are derived from the agent's system prompt and the offending tool call (not the generic fixed fields from the old Action App)

🤖 Generated with Claude Code

…alations

When a guardrail fires and triggers an escalation, the agent's own LLM
now generates a HitlSchema from the full conversation context —
system prompt, user request, and the offending tool call — using
`model.with_structured_output(HitlSchema)`.

The generated schema travels inline with the QuickForm task request
(via `create_quickform_async`). No pre-deployed Action App is required.

Implementation:
- `EscalateAction` (agent graph path) gains an optional `model` field.
  When set, schema is generated dynamically; when absent, falls back to
  the existing static Action App path for backward compatibility.
- `create_agent` injects the model into any `EscalateAction` in the
  guardrails list before wiring subgraphs — no API change for callers.
- Middleware `EscalateAction` is unchanged (no state.messages access).

Depends on: UiPath/uipath-python#1737 (HitlSchema types + QuickForm dispatch)
_SCHEMA_GEN_PROMPT = SystemMessage(
"A guardrail policy was violated during the agent's tool execution. "
"Based on the conversation above — including the agent's purpose, the user's request, "
"and the tool call that triggered the violation — generate a human review form schema. "

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.

The violation can be triggered by 3 types of calls: tool, llm, agent.
Please consider all possible scopes

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