validate_partita_iva_format
Validate an Italian Partita IVA by verifying it has exactly 11 digits and passes the official checksum. Use this as the first step in invoice generation to prevent errors.
Instructions
Validate an Italian Partita IVA for format (11 digits) and modulo-10 checksum.
Use this as step 1 in the invoice generation workflow before any other tool. Equivalent to validate_partita_iva() in header tools — use this standalone version when you only need the validation result without importing header tools.
Strips whitespace, checks for exactly 11 digits, then applies the official Agenzia delle Entrate control algorithm to verify the check digit.
On success returns {'valid': true, 'value': '<cleaned_piva>'}. On failure returns {'valid': false, 'value': '', 'error': ''}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| partita_iva | Yes | Italian Partita IVA (VAT number) to validate. Must be exactly 11 digits. Whitespace is stripped before validation. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- tools/global_tools.py:689-741 (handler)The actual handler function that validates an Italian Partita IVA: strips whitespace, checks 11-digit format, computes modulo-10 checksum per Agenzia delle Entrate algorithm.
@mcp.tool() def validate_partita_iva_format( partita_iva: Annotated[ str, Field( description=( "Italian Partita IVA (VAT number) to validate. " "Must be exactly 11 digits. Whitespace is stripped before validation." ) ), ], ) -> dict: """Validate an Italian Partita IVA for format (11 digits) and modulo-10 checksum. Use this as step 1 in the invoice generation workflow before any other tool. Equivalent to validate_partita_iva() in header tools — use this standalone version when you only need the validation result without importing header tools. Strips whitespace, checks for exactly 11 digits, then applies the official Agenzia delle Entrate control algorithm to verify the check digit. On success returns {'valid': true, 'value': '<cleaned_piva>'}. On failure returns {'valid': false, 'value': '<input>', 'error': '<reason>'}. """ piva = partita_iva.strip() if not re.match(r"^\d{11}$", piva): return { "valid": False, "value": piva, "error": "Partita IVA must be exactly 11 digits.", } total = 0 for i, digit in enumerate(piva[:10]): d = int(digit) if i % 2 == 1: d *= 2 if d > 9: d -= 9 total += d expected = (10 - (total % 10)) % 10 actual = int(piva[10]) if expected != actual: return { "valid": False, "value": piva, "error": f"Checksum mismatch: expected {expected}, got {actual}.", } return {"valid": True, "value": piva} - tools/global_tools.py:86-87 (registration)Registration function that wraps the tool with @mcp.tool() decorator, registering it on the FastMCP instance.
def register_global_tools(mcp: FastMCP) -> None: """Register the 7 global FatturaPA tools on the FastMCP instance.""" - server.py:83-85 (registration)Top-level registration call in server.py entry point that triggers tool registration.
register_header_tools(mcp) register_body_tools(mcp) register_global_tools(mcp) - tools/global_tools.py:691-700 (schema)Pydantic Field annotation defining the input schema for the partita_iva parameter.
partita_iva: Annotated[ str, Field( description=( "Italian Partita IVA (VAT number) to validate. " "Must be exactly 11 digits. Whitespace is stripped before validation." ) ), ], ) -> dict: