Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions examples/agents_api/apps/document_review/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,27 @@ def validate_review(report: dict[str, Any], document: str) -> None:
for item in line_items
]
shipping = Decimal(str(calculation["shipping"]))
stated_subtotal = Decimal(str(calculation["stated_subtotal"]))
stated = Decimal(str(report["amount"]))
calculated = Decimal(str(calculation["calculated_total"]))
difference = Decimal(str(calculation["difference"]))
if not all(
value.is_finite()
for value in [*amounts, shipping, stated, calculated, difference]
for value in [
*amounts,
shipping,
stated_subtotal,
stated,
calculated,
difference,
]
):
raise ValueError("Invoice amounts must be finite")
if sum(amounts) + shipping != calculated or stated - calculated != difference:
if (
sum(amounts) != stated_subtotal
or stated_subtotal + shipping != calculated
Comment on lines +109 to +110

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.

P1 Badge Permit reports to describe subtotal mismatches

For an invoice whose printed subtotal differs from the sum of its line items—the financial discrepancy this change is intended to surface—the specialist must report the printed value as stated_subtotal, but this check rejects that factual report and aborts the entire batch in validate_review. The policy instead needs to let the report retain both values and produce an escalated decision; otherwise invoices with an incorrect printed subtotal cannot be reviewed or returned to the human approver.

Useful? React with 👍 / 👎.

or stated - calculated != difference
):
raise ValueError("Invoice totals do not match the extracted line items")
except (KeyError, TypeError, ValueError, InvalidOperation) as error:
raise ValueError(f"{document}: invalid invoice calculation: {error}") from error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Write `/workspace/output/<document-stem>.json` with the following fields:
"recommendation": "Escalate for human review.",
"calculation": {
"line_items": [{"quantity": 2, "unit_price": 100}],
"stated_subtotal": 200,
"shipping": 20,
"calculated_total": 220,
"difference": 6200
Expand All @@ -56,8 +57,10 @@ Write `/workspace/output/<document-stem>.json` with the following fields:

Every `issues` entry must be a plain-English string, not a nested object.
Use the actual document values, not the illustrative numbers above. Include every
invoice line item in `calculation`; `amount` is the stated total. For contracts,
set `document_type` to `contract` and `calculation` to `null`.
invoice line item in `calculation`; `stated_subtotal` is the printed subtotal,
`amount` is the stated total, and `calculated_total` must equal
`stated_subtotal + shipping`. For contracts, set `document_type` to `contract`
and `calculation` to `null`.

Only the coordinator writes `summary.json`. A specialist writes its assigned report.

Expand Down