{"skill":{"slug":"guardrailsfor-agent","displayName":"GuardRails","summary":"Build, run, and extend the Agent Policy & Guardrails Engine. Use when implementing policy formats, enforcement logic, decision conflict resolution, policy AP...","description":"---\nname: agent-policy-guardrails-engine\ndescription: Build, run, and extend the Agent Policy & Guardrails Engine. Use when implementing policy formats, enforcement logic, decision conflict resolution, policy APIs, and audit/compliance workflows.\n---\n\n# Agent Policy & Guardrails Engine\n\n## Use This Skill When\n\n- You need to add or change policy enforcement behavior.\n- You need to add policy types (financial, privacy, communication, operational, approval, time-based).\n- You need to extend decision outputs (`ALLOW`, `DENY`, `MODIFY`, `REQUIRE_APPROVAL`).\n- You need to update APIs, persistence, or audit logging.\n\n## Project Layout\n\n- `app/main.py`: FastAPI endpoints.\n- `app/service.py`: orchestration for policy CRUD + evaluation + audit writes.\n- `app/engine.py`: core policy evaluation and conflict resolution.\n- `app/policy_parser.py`: JSON/YAML/NL policy parsing into structured definitions.\n- `app/schemas.py`: request/response and policy schemas.\n- `app/models.py`: SQLAlchemy models (`policies`, `audit_logs`).\n- `app/seed.py`: baseline policies.\n- `tests/test_api.py`: API-level behavior.\n- `tests/test_engine.py`: decision logic behavior.\n\n## Standard Workflow\n\n1. Implement schema/model changes first if policy structure changes.\n2. Update parser and engine evaluation paths.\n3. Update API/service layer only as needed.\n4. Add or update tests for both engine and API.\n5. Run tests before finalizing.\n\n## Commands\n\nInstall and test:\n\n```bash\npython3 -m pip install -r requirements.txt\npython3 -m pytest\n```\n\nRun locally:\n\n```bash\npython3 -m uvicorn app.main:app --reload\n```\n\n## Enforcement Contract\n\nAll external agent/tool actions must be sent to `POST /evaluate` before execution.\n\nRuntime handling expectations:\n\n- `DENY`: block execution.\n- `REQUIRE_APPROVAL`: pause and require explicit human approval.\n- `MODIFY`: apply returned `modifications`, then execute.\n- `ALLOW`: execute.\n\n## Conflict Resolution Rules\n\nWhen multiple policies match the same action:\n\n1. Highest `priority` wins.\n2. If tied on priority, effect severity wins:\n   `DENY > REQUIRE_APPROVAL > MODIFY > ALLOW`.\n\n## Adding New Guardrails\n\n1. Add a structured policy in `app/seed.py` (optional baseline).\n2. Ensure `action_types` and `conditions` map to real runtime payload fields.\n3. Add API test coverage in `tests/test_api.py` using `/evaluate`.\n4. Add engine-level tests in `tests/test_engine.py` for edge/conflict cases.\n\n## Notes\n\n- Keep policy evaluation deterministic.\n- Prefer structured JSON/YAML policies for complex controls.\n- Natural-language rules should compile into the same structured policy schema.\n","topics":["Policy"],"tags":{"latest":"1.0.2"},"stats":{"comments":0,"downloads":193,"installsAllTime":7,"installsCurrent":0,"stars":2,"versions":2},"createdAt":1771921595014,"updatedAt":1778491624313},"latestVersion":{"version":"1.0.2","createdAt":1771922018461,"changelog":"- Added a new guardrails.db file to the project.\n- This addition may provide local persistence or data support for the guardrails engine.","license":null},"metadata":null,"owner":{"handle":"adad44","userId":"s176f5kvyvnx1es4ynmt7twyyx884wd5","displayName":"adad44","image":"https://avatars.githubusercontent.com/u/198119498?v=4"},"moderation":{"isSuspicious":false,"isMalwareBlocked":false,"verdict":"clean","reasonCodes":["review.llm_review"],"summary":"Review: review.llm_review","engineVersion":"v2.4.24","updatedAt":1780089731406}}