Skip to main content

Validation Rules Reference

A complete reference of every rule Klervex applies to a shipment before it generates documents. Validation is deterministic — the same input always produces the same result — and runs in under one second.

If a rule fails, Klervex returns a structured error with the rule ID, the field path, and a specific message. Documents are not generated until the failing rules are fixed or explicitly waived.

How Validation Works

Klervex uses Rynko Flow to evaluate rules. The flow is:

  1. Schema validation — Field types, required fields, format constraints
  2. Business rule evaluation — Cross-field rules and lookup table queries
  3. Country-specific rules — Applied based on origin and destination
  4. Document-specific rules — Applied based on the requested document types

Every rule:

  • Has a unique rule ID (e.g. rule_total_matches_line_items)
  • Returns a structured error message if it fails
  • References a specific field path in the shipment data
  • Is explainable — you can see exactly why a rule failed and what to change

Error Response Format

{
"valid": false,
"score": 87,
"results": [
{
"rule_id": "rule_hs_code_us",
"category": "HS Code",
"severity": "error",
"message": "HS code 9999.99.9999 not found in US HTS schedule",
"field": "goods.line_items[0].hs_code"
}
],
"validation_hash": "sha256:a1b2c3...",
"validated_at": "2026-04-08T10:00:00Z"
}

Severity Levels

SeverityBehavior
errorBlocks document generation. Must be fixed.
warningAllows document generation but flagged for review.
infoInformational only.

Category 1 — Required Fields

Mandatory fields that must be present on every shipment.

Rule IDCheckSeverity
rule_exporter_requiredExporter name, address, and country must be presenterror
rule_importer_requiredImporter name, address, and country must be presenterror
rule_route_requiredRoute origin, destination, and transport mode must be presenterror
rule_currency_requiredCurrency must be a valid ISO 4217 three-letter codeerror
rule_has_line_itemsAt least one line item must be presenterror
rule_line_item_descriptionEach line item must have a non-empty descriptionerror
rule_line_item_quantityEach line item must declare a quantityerror
rule_line_item_unit_priceEach line item must declare a unit priceerror

Category 2 — Mathematical Consistency

Cross-field math checks that catch silent extraction errors and data entry mistakes.

Rule IDCheckSeverity
rule_positive_totalgoods.total_value > 0error
rule_positive_quantitiesEvery line item quantity must be greater than zeroerror
rule_positive_pricesEvery line item unit price must be greater than zeroerror
rule_total_matches_line_itemsgoods.total_value equals sum(line_items, quantity × unit_price)error
rule_gross_gte_net_weightGross weight must be ≥ net weight per line itemerror
rule_total_packages_consistentTotal packages count matches packages array lengthwarning
rule_total_weight_consistentTotal gross weight matches sum of package weightswarning

Example: total mismatch

{
"rule_id": "rule_total_matches_line_items",
"severity": "error",
"message": "Total value 25000 does not match sum of line items 24500",
"field": "goods.total_value",
"context": {
"declared_total": 25000,
"computed_total": 24500,
"difference": 500
}
}

Category 3 — HS Code Validation

Every line item HS code is checked against the destination country's actual tariff schedule. Klervex maintains synced lookup tables for US HTS, EU TARIC, UK Trade Tariff, and India Customs Tariff.

Rule IDCheckSeverity
rule_hs_code_formatHS code must be a 6-10 digit numeric codeerror
rule_hs_code_usWhen destination is US, HS code must exist in US HTS lookup tableerror
rule_hs_code_euWhen destination is in EU, HS code must exist in EU TARIC lookup tableerror
rule_hs_code_ukWhen destination is UK, HS code must exist in UK Trade Tariff lookup tableerror
rule_hs_code_inWhen destination is IN, HS code must exist in India Customs Tariff lookup tableerror
rule_hs_code_length_usUS destination requires 10-digit HTS codeserror
rule_hs_code_length_euEU destination requires 10-digit codeserror
rule_hs_code_length_inIndia destination requires 8-digit codeserror
rule_origin_country_per_itemEach line item must have a declared origin_countryerror

Lookup table data sources

TableSourceRefresh
hs_codes_usDerived from WCO 6-digit codes (10-digit extension)Quarterly
hs_codes_euDerived from WCO 6-digit codes (8-digit extension)Quarterly
hs_codes_ukHMRC UK Trade Tariff API (trade-tariff.service.gov.uk)Quarterly
hs_codes_inDerived from WCO 6-digit codes (8-digit extension)Quarterly
hs_codes_wcoWorld Customs Organization 6-digit referenceAnnual
duty_ratesNot populated — see note below
Duty Rates — Not Yet Implemented

The duty_rates lookup table exists but is intentionally empty. No business rules currently reference it, and no UI displays duty rate information. Duty rates are complex — they vary by trade agreements, quotas, anti-dumping measures, and seasonal adjustments. A simple MFN rate doesn't capture the full picture.

This table will be populated when Klervex adds duty estimation features (estimated landed cost, duty cost on shipment summary). Real rate sources:

  • UK: trade-tariff.service.gov.uk/api/v2/bulk_search
  • US: hts.usitc.gov/export (HTS CSV/JSON with general rate of duty)
  • EU: ec.europa.eu/taxation_customs/dds2/taric/ or CN CSV dumps

For now, HS code validation works independently of duty rates — it checks code existence, not the rate.


Category 4 — Sanctions & Party Screening

All parties named on a shipment are screened against the OFAC Specially Designated Nationals (SDN) list.

Rule IDCheckSeverity
rule_sanctions_exporterExporter not on OFAC SDN listerror
rule_sanctions_importerImporter not on OFAC SDN listerror
rule_sanctions_notify_partyNotify party (if present) not on OFAC SDN listerror
rule_embargoed_originOrigin country not on comprehensive embargo listerror
rule_embargoed_destinationDestination country not on comprehensive embargo listerror

Lookup table data sources

TableSourceRefresh
sanctions_ofacUS Treasury OFAC Specially Designated Nationals listDaily

Category 5 — Route & Transport

Route validation ensures the declared journey is physically possible and that the transport mode is consistent with the documents.

Rule IDCheckSeverity
rule_port_of_loading_validPort of loading must be a valid UN/LOCODEerror
rule_port_of_discharge_validPort of discharge must be a valid UN/LOCODEerror
rule_port_country_match_originPort of loading must be in the declared origin countrywarning
rule_port_country_match_destPort of discharge must be in the declared destination countrywarning
rule_exporter_country_matches_originexporter.country must equal route.origin_countryerror
rule_importer_country_matches_destimporter.country must equal route.destination_countryerror
rule_transport_mode_validTransport mode must be one of: sea, air, road, rail, multimodalerror

Lookup table data sources

TableSourceRefresh
port_codesUNECE UN/LOCODE databaseQuarterly

Category 6 — Incoterms 2020

Incoterms must be a valid 2020 code and compatible with the declared transport mode.

Rule IDCheckSeverity
rule_incoterms_valid_2020Must be one of: EXW, FCA, CPT, CIP, DAP, DPU, DDP, FAS, FOB, CFR, CIFerror
rule_incoterms_sea_onlyFAS, FOB, CFR, CIF only valid with sea or inland waterway transporterror
rule_incoterms_2010_deprecatedOld 2010 codes (DAT, DAF, DES, DEQ, DDU) are no longer acceptederror

Sea-only Incoterms

CodeFull nameRequired transport mode
FASFree Alongside ShipSea or inland waterway
FOBFree On BoardSea or inland waterway
CFRCost and FreightSea or inland waterway
CIFCost, Insurance, and FreightSea or inland waterway

Multimodal Incoterms

CodeFull nameCompatible transport modes
EXWEx WorksAny
FCAFree CarrierAny
CPTCarriage Paid ToAny
CIPCarriage and Insurance Paid ToAny
DAPDelivered at PlaceAny
DPUDelivered at Place UnloadedAny
DDPDelivered Duty PaidAny

Category 7 — Country-Specific Compliance

Country-specific rules that apply based on the origin or destination jurisdiction.

United States

Rule IDCheckSeverity
rule_us_hts_10_digitUS destination requires 10-digit HTSUS code per line itemerror
rule_us_ein_formatIf exporter has EIN, must be in XX-XXXXXXX formatwarning

European Union

Rule IDCheckSeverity
rule_eu_eori_requiredEU destination requires importer EORIerror
rule_eu_eori_formatEORI must follow <country><digits> format (e.g. DE123456789012345)error
rule_eu_taric_10_digitEU destination requires 10-digit TARIC code per line itemerror

United Kingdom

Rule IDCheckSeverity
rule_uk_eori_gb_prefixUK destination requires GB-prefixed EORI (post-Brexit)error
rule_uk_eori_formatFormat GB<9 digits> or GB<12 digits>error

India

Rule IDCheckSeverity
rule_in_iec_requiredIndia destination requires importer IEC (Importer-Exporter Code)error
rule_in_iec_formatIEC must be a 10-character alphanumeric codeerror
rule_in_gstin_formatIf GSTIN provided, must match 15-character GST formatwarning
rule_in_pan_formatPAN must match [A-Z]{5}[0-9]{4}[A-Z]warning

Category 8 — Document-Specific Rules

Per-document rules that apply only when the relevant document type is being generated.

Rule IDDocumentCheckSeverity
rule_doc_bl_sea_onlyBill of LadingTransport mode must be sea or multimodal with sea legerror
rule_doc_awb_air_onlyAir WaybillTransport mode must be airerror
rule_doc_coo_origin_per_itemCertificate of OriginEach line item requires origin_countryerror
rule_doc_dgd_un_classificationDangerous Goods DeclarationHazardous items need UN number, hazard class, packing grouperror
rule_doc_vgm_sea_containerVGM DeclarationTransport mode must be sea and packaging.containers must be presenterror
rule_doc_vgm_method_validVGM DeclarationWeighing method must be 1 (entire weighed) or 2 (sum of contents)error
rule_doc_eur1_agreementEUR.1 Movement Certificatepreferential_origin.agreement_name must be seterror
rule_doc_usmca_partiesUSMCA Certificate of OriginAt least one party must be in US, MX, or CAerror
rule_doc_phyto_botanicalPhytosanitary CertificateEach plant product requires botanical nameerror
rule_doc_health_vet_authorityHealth/Veterinary CertificateCompetent authority and inspection date requirederror
rule_doc_coa_test_resultsCertificate of AnalysisAt least one test result row requirederror

Category 9 — Format Validation

Schema-level format checks for individual fields.

Rule IDCheckSeverity
rule_format_iso_countryAll country fields must be ISO 3166-1 alpha-2 (two uppercase letters)error
rule_format_iso_currencyCurrency must be ISO 4217 (three uppercase letters)error
rule_format_emailContact emails must be valid email formatwarning
rule_format_phonePhone numbers must contain only digits, spaces, +, -, ()warning
rule_format_date_iso8601All date fields must be ISO 8601 formaterror
rule_format_postal_code_usUS postal codes must be 5 or 9 digitswarning

Requesting New Rules

The rule library is curated by the Klervex team and updated as customs regulations change. If you need a rule that isn't in the list above — for example, a country-specific check, a new document type, or an industry-specific compliance requirement — please reach out at [email protected].

We prioritise rule additions that benefit multiple customers over single-team customizations.


Rule Updates

The Klervex rule library is updated as customs regulations change. Recent changes:

DateChange
2026-04Added USMCA Certificate of Origin rules
2026-04Added VGM Declaration rules (SOLAS)
2026-04Added EUR.1 Movement Certificate rules
2026-04Added Phytosanitary, Health/Veterinary, COA document rules
2026-03Added India IEC and GSTIN format checks
2026-03Updated EU TARIC lookup table to current version
2026-02Added comprehensive Incoterms 2020 transport mode validation

Try It

Want to see the rules running on your own data?

  1. Sign up at app.klervex.com (free tier: 5 shipments/month)
  2. Upload a commercial invoice or enter shipment data manually
  3. Click Validate — you'll see exactly which rules pass, which fail, and why

Or use the REST API:

curl -X POST https://app.klervex.com/api/v1/shipments/validate \
-H "Authorization: Bearer klv_your_api_key" \
-H "Content-Type: application/json" \
-d @shipment.json

The response includes the full rule evaluation result — every rule that ran, every pass and fail, and the validation hash for downstream verification.