validate_partita_iva
Validates Italian Partita IVA numbers using the official checksum algorithm. Use for B2B invoices, supplier validation, and compliance.
Instructions
Validates an Italian Partita IVA (VAT number for companies and self-employed) — an 11-digit number issued by the Italian Revenue Agency. Applies the official Luhn-variant checksum algorithm used by Italian tax authorities. Returns { valid: boolean, partita_iva: string } or { valid: false, reason: string }. Use when processing Italian B2B invoices, validating Italian suppliers, or any Italian business compliance workflow.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| partita_iva | Yes | 11-digit Italian Partita IVA, with or without spaces. Example: '12345670017' |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| valid | Yes | ||
| partita_iva | No | ||
| reason | No |
Implementation Reference
- index.js:301-318 (registration)The tool 'validate_partita_iva' is registered via server.registerTool() with its description, input/output schemas, and handler. The registration includes the Italian Partita IVA description, input schema (11-digit string), output schema (valid boolean, partita_iva string optional, reason string optional), and annotations.
// ── 13. Validate Italian Partita IVA ── server.registerTool("validate_partita_iva", { description: "Validates an Italian Partita IVA (VAT number for companies and self-employed) — an 11-digit number issued by the Italian Revenue Agency. Applies the official Luhn-variant checksum algorithm used by Italian tax authorities. Returns { valid: boolean, partita_iva: string } or { valid: false, reason: string }. Use when processing Italian B2B invoices, validating Italian suppliers, or any Italian business compliance workflow.", inputSchema: { partita_iva: z.string().describe("11-digit Italian Partita IVA, with or without spaces. Example: '12345670017'") }, outputSchema: { valid: z.boolean(), partita_iva: z.string().optional(), reason: z.string().optional() }, annotations: { title: "Validate Italian Partita IVA", readOnlyHint: true, idempotentHint: true, openWorldHint: false } }, async ({ partita_iva }) => { const clean = partita_iva.replace(/\s/g, ""); if (!/^\d{11}$/.test(clean)) return { content: [{ type: "text", text: JSON.stringify({ valid: false, reason: "Partita IVA must have exactly 11 digits" }) }] }; let sum = 0; for (let i = 0; i < 10; i++) { let digit = parseInt(clean[i]); if (i % 2 === 1) { digit *= 2; if (digit > 9) digit -= 9; } sum += digit; } const valid = (10 - (sum % 10)) % 10 === parseInt(clean[10]); return { content: [{ type: "text", text: JSON.stringify({ valid, partita_iva: clean }) }] }; }); - index.js:307-318 (handler)The handler function for validate_partita_iva. It cleans whitespace, checks for exactly 11 digits, applies the Luhn-variant checksum algorithm (doubling odd-positioned digits, summing, and validating the check digit at position 10), and returns {valid, partita_iva} or {valid: false, reason}.
}, async ({ partita_iva }) => { const clean = partita_iva.replace(/\s/g, ""); if (!/^\d{11}$/.test(clean)) return { content: [{ type: "text", text: JSON.stringify({ valid: false, reason: "Partita IVA must have exactly 11 digits" }) }] }; let sum = 0; for (let i = 0; i < 10; i++) { let digit = parseInt(clean[i]); if (i % 2 === 1) { digit *= 2; if (digit > 9) digit -= 9; } sum += digit; } const valid = (10 - (sum % 10)) % 10 === parseInt(clean[10]); return { content: [{ type: "text", text: JSON.stringify({ valid, partita_iva: clean }) }] }; });