Docs · Validators
gtin validator
GS1 GTIN-8/12/13/14 with trailing-digit checksum.
Reference
Format
Strips whitespace, then matches 8, 12, 13, or 14 digits and verifies the GS1 mod-10 trailing-digit checksum.
Examples
- 7613034626844 (GTIN-13, EAN)
- 00012345600012 (GTIN-14, SSCC-style)
- 0123456789012 (GTIN-13 with leading zero — keep as string!)
How it runs
Implementation
A faithful summary of lib/validators.ts. Validators are pure functions and run identically in the Worker, the Workbench and the MCP server — one implementation, so the three cannot disagree about whether a value is valid.
function validGtin(value) {
const v = value.replace(/\s+/g, '')
if (!/^\d{8}$|^\d{12,14}$/.test(v)) {
return fail('gtin_format', 'expected 8/12/13/14 digits')
}
const digits = v.split('').map(Number)
const check = digits.pop()
const sum = digits.reverse().reduce(
(acc, d, i) => acc + d * (i % 2 === 0 ? 3 : 1), 0,
)
const want = (10 - (sum % 10)) % 10
return check === want ? OK : fail('gtin_checksum', 'bad GTIN checksum')
}Config
Use in a template
Validators attach to a field on a custom template. The cascade runs them after mapping but before commit; failures surface in the per-row validation report.
fields:
- column: gtin
type: string
validators:
- type: gtinWatch out
Common gotchas
- Leading zeros are significant. Always send GTINs as strings — Excel/JSON parsers that coerce to number will silently drop them and fail the format check.
- GTIN-11 is intentionally not accepted (not a GS1 form). GTIN-9, 10 are also rejected.
- The reserved Restricted Circulation range (RCN) passes if the checksum is valid; we do not flag GS1 prefix semantics.
Where it runs
Three routes, no AI cost.
- POST
/v1/validate-rowValidate one row against a template. Stateless, no key, pure compute — the fastest way to try gtin against a real value.no key - POST
/v1/uploads/:id/validateRun every field validator over the parsed upload, without committing. Returns errors and warnings per row.read - POST
/v1/uploads/:id/commitValidates on the way out.skip_invalid_rowsdrops the failures instead of failing the commit.commit
Validators are pure functions, so they add nothing to the AI bill. Every map draws a small flat per-map fee from your prepaid token wallet ($10 minimum, shared across the phi-cloud suite); only columns that reach the metered LLM layer, plus any-to-any convert and structural reshape, bill real AI tokens. See pricing
Catalogue
Related templates
- Drug formulary
drug_formulary_v1ATC/GTIN-coded drug catalog. Emits FHIR Medication.
Fields ·
gtin - Supplier inventory
supplier_inventory_v1Supplier catalogue with GTIN/IBAN/GLN.
Fields ·
gtin - Products
products_v1Product catalog: SKU, GTIN, price, category, weight, stock flag.
Fields ·
gtin
Explore
All 19 validator types
The complete list a template field can declare. There is no SNOMED validator — it required an affiliate licence, no template used it, and it was removed in 2026.
- gtin
- regex
- enum
- date_range
- number_range
- phone
- url
- iban
- bic
- uuid
- pharmacode
- fhir_reference
- loinc_code
- icd10_code
- atc_code
- cpt_code
- npi
- gln
Back to the documentation index or browse the template catalogue.
Ready when you are
Validate every row — before it lands.
Attach checksum-strict validators to any field, and gate risky commits behind the requires_hitl flag. One key runs the whole cascade.