find_invoice_anomalies
Detect inconsistencies and anomalies in FatturaPA XML documents to validate invoice totals, VAT, dates, P.IVA, destination codes, line items, negative amounts, and payment data.
Instructions
Detect inconsistencies and anomalies in a FatturaPA XML document.
Checks eight anomaly categories: document total mismatch, VAT calculation error, future invoice date, invalid Italian P.IVA checksum, missing or suspicious destination code, incomplete line items, unjustified negative amount, and missing payment data. Never logs or persists XML content.
When file_path is given the document is read from disk; the path is
checked against the roots configured in FATTURAPA_ALLOWED_ROOTS before
any read is attempted. Pass xml_content directly to skip file I/O.
Args: xml_content: Raw XML string of the FatturaPA document. ctx: Optional MCP context for structured log emission. file_path: Optional filesystem path to read the document from. Checked against allowed roots before reading.
Returns: A FindAnomaliesResult with keys: anomalies_found (int): Total number of anomalies detected. anomalies (list): All anomaly records. warnings (list): Only warning-severity anomalies. errors (list): Only error-severity anomalies. is_clean (bool): True when no anomalies are found.
Raises: PermissionError: If file_path is outside the configured allowed roots. ValueError: If neither xml_content nor file_path is provided. lxml.etree.XMLSyntaxError: If the XML is not well-formed.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | No | ||
| xml_content | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| errors | Yes | ||
| is_clean | Yes | ||
| warnings | Yes | ||
| anomalies | Yes | ||
| anomalies_found | Yes |