Skip to content

Latest commit

 

History

History
169 lines (127 loc) · 5.77 KB

llm-agent-integration.md

File metadata and controls

169 lines (127 loc) · 5.77 KB

LLM Agent Integration

Use this guide when an LLM agent, approval workflow assistant, or service reads lfpolicy JSON output. This is runtime integration guidance, not coding agent guidance for modifying this repository. Repository coding agents should start with ../AGENTS.md.

Backend services should invoke lfpolicy through the CLI module and consume JSON artifacts. See service-integration.md for the subprocess contract boundary.

Core Rule

Separate technical severity from workflow action.

  • severity describes the governance signal produced by lfpolicy.
  • recommended_action tells the consuming workflow what to do next.
  • hard_block is a boolean shortcut for recommended_action: "block".

Do not convert every severity: "error" into a user-facing block. In advisory flows, many errors mean "policy risk found; get review or approval", not "execution is impossible".

Action Meanings

recommended_action Agent behavior User-facing language
inform Show as context only. 참고
review_required Summarize evidence and route to a reviewer. 검토 필요
approval_required Ask for explicit approval, exception metadata, or ticket evidence. 승인 필요
block Stop the workflow until the policy or request changes. 차단 사유

Use hard_block: true only for "cannot proceed" language. Otherwise, prefer "검토 필요", "승인 필요", or "정책상 위험 항목 발견".

Review Bundle Decision Rules

Read review/summary.json first.

  1. If status is blocked, stop. Explain blocking_reasons.
  2. If any record has hard_block: true, stop even if the caller did not inspect summary.json first.
  3. If recommended_action is approval_required, request approval evidence, exception metadata, or a linked ticket before continuing.
  4. If recommended_action is review_required, summarize the plan, lint, and audit evidence for a human reviewer.
  5. If recommended_action is inform, show the finding only as context.
  6. Do not execute AWS writes from a review bundle alone. lfpolicy has no apply command in 0.9.0 and later; consuming services own approval and execution.

Recommended review summary handling:

{
  "status": "review_required",
  "recommended_action": "approval_required",
  "action_summary": {
    "inform": 0,
    "review_required": 1,
    "approval_required": 1,
    "block": 0
  },
  "blocking_reasons": []
}

The correct interpretation is: "This is not blocked, but it needs approval or reviewer action before proceeding."

Finding And Change Rules

For lint.json, audit.json, and plan.json, inspect each item:

{
  "severity": "error",
  "recommended_action": "approval_required",
  "hard_block": false
}

The correct interpretation is: "This is a serious governance signal, but the workflow should request approval rather than claim the request is impossible."

Examples:

  • Broad principal, SUPER, mutating grant, grant option, or named grant: usually approval_required.
  • Safe additive grant or drift evidence: usually review_required.
  • IAM_ALLOWED_PRINCIPALS_PRESENT: migration-readiness evidence that requires review, but is not a hard block and must not trigger an automatic revoke.
  • Expired exception, duplicate identity, invalid LF-Tag reference, invalid permission combination, or destructive planned change: usually block.

Explain Rules

review/explain.json is planned grant-change evidence. It answers:

  • What grant changes are planned?
  • Which principal/resource/permissions are involved?
  • What was before and what would be after?
  • Why is the grant change planned?

It does not answer arbitrary access questions. Do not use it to tell a user why someone currently can or cannot access a table.

For operational access questions, use explain-batch:

lfpolicy explain-batch \
  --requests access-requests.json \
  --current-snapshot current.json \
  --output json

Only treat an access request as allowed when the result decision is allowed. If a grant matches the principal and resource but lacks the requested permission, the decision remains denied. An iam_allowed_principals explain finding has status: "context" because lfpolicy does not model the caller's AWS IAM authorization. Do not convert that context finding into an allowed decision.

Prompting Pattern

When an LLM agent summarizes a review bundle, use this order:

  1. State the review status and recommended_action.
  2. If blocked, list blocking_reasons and stop.
  3. Summarize planned safe changes.
  4. Summarize approval-required risks and their tickets or missing metadata.
  5. Point to explain-batch for current access decisions.
  6. Avoid saying "failed" unless status is blocked.

Good wording:

검토 필요입니다. 차단 사유는 없습니다. 다만 broad permission grant가 있어
승인 필요 항목으로 표시됩니다. 티켓/승인자/만료일을 확인한 뒤 진행하세요.

Bad wording:

오류가 있으므로 권한 부여가 불가능합니다.

That wording incorrectly treats severity: "error" as a hard block.

Required Inputs For Exceptions

Exception records must include:

  • ticket
  • owner
  • approved_by
  • reason
  • expires_at

Expired exceptions are hard-block candidates. Exceptions expiring soon and exceptions where owner equals approved_by should be surfaced as review warnings, not hidden.

Do Not

  • Do not infer approval from passed, review_required, or approval_required.
  • Do not trigger AWS write execution automatically from any JSON report.
  • Do not use severity alone for workflow decisions.
  • Do not describe review planned-grant evidence as effective-access evidence.
  • Do not hide hard_block findings behind a generic summary.