Decision explainer
A panel that answers "why was this refused?" with the rule that decided and the next step.
Identity systems refuse often. This panel turns a refusal into something that a developer or an administrator can act on: the question, the reason, what decided, and the next step.
Installation
- CLI
- Manual
The command adds the file to your project, with the shadcn/ui components that it uses. Your project needs shadcn/ui.
- pnpm
- npm
- yarn
- bun
pnpm dlx shadcn@latest add https://examples.lumoauth.dev/r/decision-explainer.json
npx shadcn@latest add https://examples.lumoauth.dev/r/decision-explainer.json
yarn dlx shadcn@latest add https://examples.lumoauth.dev/r/decision-explainer.json
bunx --bun shadcn@latest add https://examples.lumoauth.dev/r/decision-explainer.json
Add the shadcn/ui components that the pattern uses.
npx shadcn@latest add buttonInstall the packages.
npm install lucide-reactCopy the code into your project.
components/decision-explainer.tsximport * as React from 'react';import { Ban, Check, ArrowRight } from 'lucide-react';import { Button } from '@/components/ui/button';import { cn } from '@/lib/utils';/** What decided: a capability of the agent, a policy, or a deny rule. */export type DecidedBy = 'capability' | 'pdp' | 'deny_override';export interface DecisionData {allowed: boolean;/** Who asked: the name of the agent or of the person. */subject: string;/** The action that was asked about, for example `invoices:refund`. */action: string;/** The resource, when the question named one. */resource?: string | null;/** The reason that LumoAuth gave. */reason?: string | null;decidedBy?: DecidedBy | string | null;/** The ID of the audit record. */auditId?: string | null;}/** Maps the answer of the Ask API (`agent.ask()`) to a decision. */export function fromAskResult(subject: string,result: {allowed: boolean;action: string;reason?: string | null;audit_id?: string | null;context?: Record<string, unknown> | null;[key: string]: unknown;},): DecisionData {return {allowed: result.allowed,subject,action: result.action,resource: typeof result.context?.resource === 'string' ? result.context.resource : null,reason: result.reason ?? null,decidedBy: typeof result.decided_by === 'string' ? result.decided_by : null,auditId: result.audit_id ?? null,};}const SOURCE: Record<string, { name: string; refused: string }> = {capability: {name: 'The capabilities of the agent',refused: 'The agent does not hold a capability that covers this action. A person can approve it for one task, or an administrator can add the capability.',},pdp: {name: 'A policy',refused: 'A policy of your organization says no for this subject and this resource. An administrator can change the policy.',},deny_override: {name: 'A deny rule',refused: 'A deny rule blocks this action. A deny rule wins over every grant, so an approval cannot lift it.',},};export interface NextStep {label: string;onClick?: () => void;href?: string;}export interface DecisionExplainerProps {decision: DecisionData;/** What the reader can do next. Leave it out for a decision that needs no action. */nextSteps?: NextStep[];className?: string;}export function DecisionExplainer({ decision, nextSteps = [], className }: DecisionExplainerProps) {const source = decision.decidedBy ? SOURCE[decision.decidedBy] : undefined;const Icon = decision.allowed ? Check : Ban;return (<section className={cn('w-full max-w-md rounded-lg border bg-card text-sm text-card-foreground', className)} aria-label="Authorization decision"><header className="flex items-start gap-3 p-4"><spanclassName={cn('mt-0.5 flex size-7 shrink-0 items-center justify-center rounded-full',decision.allowed ? 'bg-emerald-500/15 text-emerald-700 dark:text-emerald-400' : 'bg-red-500/15 text-red-700 dark:text-red-400',)}><Icon className="size-4" aria-hidden="true" /></span><div className="grid gap-1"><p className="font-medium">{decision.allowed ? 'Allowed' : 'Refused'}</p><p className="text-muted-foreground"><span className="font-medium text-foreground">{decision.subject}</span> asked to{' '}<code className="font-mono text-[0.8125rem] text-foreground">{decision.action}</code>{decision.resource && (<>{' '}on <code className="font-mono text-[0.8125rem] text-foreground">{decision.resource}</code></>)}.</p></div></header><dl className="grid gap-3 border-t p-4"><div className="grid gap-0.5"><dt className="text-xs font-medium tracking-wide text-muted-foreground uppercase">Why</dt><dd>{decision.reason ?? (decision.allowed ? 'A grant covers this action.' : 'No grant covers this action.')}</dd></div>{source && (<div className="grid gap-0.5"><dt className="text-xs font-medium tracking-wide text-muted-foreground uppercase">What decided</dt><dd>{source.name}{!decision.allowed && <span className="text-muted-foreground">. {source.refused}</span>}</dd></div>)}</dl>{(nextSteps.length > 0 || decision.auditId) && (<footer className="flex flex-wrap items-center gap-2 border-t p-4">{nextSteps.map((step, index) =>step.href ? (<a key={step.label} href={step.href} className="inline-flex items-center gap-1 font-medium underline underline-offset-4">{step.label}<ArrowRight className="size-3.5" aria-hidden="true" /></a>) : (<Button key={step.label} size="sm" variant={index === 0 ? 'default' : 'outline'} onClick={step.onClick}>{step.label}</Button>),)}{decision.auditId && <span className="ml-auto font-mono text-xs text-muted-foreground">{decision.auditId}</span>}</footer>)}</section>);}Change the import paths if your project keeps its components in another place.
Usage
fromAskResult maps the answer of the Ask API. Add the next steps that make sense in your app.
import { DecisionExplainer, fromAskResult } from '@/components/decision-explainer';
export function Refusal({ agentName, answer, onAskApproval }: { agentName: string; answer: any; onAskApproval: () => void }) {
return (
<DecisionExplainer
decision={fromAskResult(agentName, answer)}
nextSteps={answer.decided_by === 'deny_override' ? [] : [{ label: 'Ask for approval', onClick: onAskApproval }]}
/>
);
}
Offer no approval for a deny rule: a deny rule wins over every grant, so an approval cannot lift it.
Where the data comes from
| What the pattern shows | Call |
|---|---|
| A decision for an agent | agent.ask(action, context): allowed, reason, decided_by, audit_id |
| A decision for a person | lumo.permissions.checkDetailed() |
| The audit record | Admin API, audit logs |
States
- Allowed.
- Refused by a policy.
- Refused by a deny rule, with the audit ID.
Props
| Prop | Type | Description |
|---|---|---|
decisionrequired | DecisionData | The decision. |
nextSteps | { label: string; onClick?: () => void; href?: string }[] | What the reader can do next. A step with href is a link, the others are buttons. |
className | string | Class name for the panel. |
DecisionData
| Option | Type | Description |
|---|---|---|
allowedrequired | boolean | The answer. |
subjectrequired | string | Who asked: the name of the agent or of the person. |
actionrequired | string | The action that was asked about. |
resource | string | null | The resource, when the question named one. |
reason | string | null | The reason that LumoAuth gave. |
decidedBy | 'capability' | 'pdp' | 'deny_override' | What decided: a capability of the agent, a policy, or a deny rule. |
auditId | string | null | The ID of the audit record. |