Skip to content

feat(sdk): add conditional output lifts with external data sources#231

Open
yazcaleb wants to merge 2 commits into
masterfrom
capy/conditional-output-lifts
Open

feat(sdk): add conditional output lifts with external data sources#231
yazcaleb wants to merge 2 commits into
masterfrom
capy/conditional-output-lifts

Conversation

@yazcaleb
Copy link
Copy Markdown
Collaborator

@yazcaleb yazcaleb commented May 11, 2026

This PR adds conditional lifts to output rules via unless clauses, custom context passthrough, and external condition sources with caching.

Output rule lifts

  • Added unless clause on OutputRule that suppresses actions when all conditions evaluate true
  • OutputValidator now returns liftedRuleIds and liftTrace in results for auditability
  • Supports all condition operators (equals, matches, etc.) within unless clauses
  • Lifts work with redact, block, and log actions for comprehensive conditional control

Custom context passthrough

  • validateOutput and validateOutputAsync now accept OutputValidationContext with optional custom field
  • Custom context flows into evaluation context as context.* for unless conditions
  • condition-evaluato.ts resolves context.custom values for context.field references

External condition sources

  • Added ConditionSourceConfig types for webhook, custom_context, and placeholder types
  • Webhook sources POST JSON { source, params } and cache responses per TTL
  • Custom context sources read from ValidationContext.custom with optional dot-path resolution
  • LRU cache with cache_ttl and stale-while-revalidate for async lookups
  • Webhook sources support environment variable expansion in url and auth headers

Schema changes

  • RuleSet.condition_sources maps names to ConditionSourceConfig
  • RuleCondition now has optional source and params fields
  • Policy IR v1 schema updated with ConditionSource definition and new condition properties

Tests

  • Test verifies lift on custom context match (context.nda_signed: true)
  • Test verifies webhook resolution, caching, and fail-closed behavior on 503
  • Webhook fetch mock validates POST body, auth header, and single-call caching

Open SCO-187 SCO-187

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@yazcaleb yazcaleb requested a review from anirudhp26 as a code owner May 11, 2026 22:04
@yazcaleb yazcaleb added the capy Generated by capy.ai label May 11, 2026 — with Capy AI
@github-actions github-actions Bot added area:sdk Changes in the TypeScript SDK area:docs Documentation updates labels May 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Copy Markdown
Contributor

@capy-ai capy-ai Bot left a comment

Choose a reason for hiding this comment

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

Added 1 comment

Comment thread packages/sdk/src/core/output-validator.ts Outdated
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Documentation updates area:sdk Changes in the TypeScript SDK capy Generated by capy.ai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant