ExportFlowDevelopers
Sign inGet API keys

Guides

Verification

A verification checks what a shipment's documents say against each other and against a published rule set. It reports evidence of inconsistency. It never certifies that a shipment is compliant.

The record#

Once a shipment’s documents are processed, the API can tell you what they say as one record: for each field, every document’s reading of it. More than one distinct value for a field is a disagreement between documents, which is exactly what verification exists to find.

record = client.records.get(shipment.id)
for field in record.fields:
    values = field.distinct_values()
    if len(values) > 1:
        print(field.name, "is read differently across documents:", values)

Why the record must be confirmed first#

Starting a verification on an unconfirmed record is refused with 409 and the code not_confirmed. This is the one step the API will not do for you, and the reason is the product’s whole purpose.

Extraction can misread a field. If it did, every finding computed from that field would be wrong, in both directions: a real discrepancy hidden, or a false one reported. So a person looks at what was read, next to the document, and confirms it. Only then are the documents checked.

Confirm what the document says, not what it should say

If the bill of lading shows the wrong port, confirm the wrong port. Correcting it at this step would hide the very error verification is there to find. Confirmation fixes misreadings of the document; verification finds mistakes in the document.

# The short form: field name to the value the document shows.
client.records.confirm(shipment.id, {"port_of_discharge": "NHAVA SHEVA"})

# The full form: cite the reading a value came from, or record an absence.
client.records.confirm(shipment.id, [
    {"name": "bl_number", "value": "MEDU7741203", "source_extraction_id": extraction_id},
    {"name": "lc_number", "absence_reason": "not_applicable"},
])

A confirmed field is one of two things:

  • a value, optionally with source_extraction_id naming the reading it came from, which must belong to one of this shipment’s documents;
  • an absence_reason: not_applicable when the field does not apply to this shipment, or missing_from_documents when it should be there and is not.

You can confirm in several calls, and confirm a field again to change it. The record counts as confirmed once at least one field is. In your product, show your user the readings and let them confirm or correct each; do not confirm on their behalf.

Running a verification#

POST /shipments/{id}/verifications answers 202 with the verification in the queued state. It moves through running to complete, or to failed with a failure_reason. Poll GET /verifications/{id}, or subscribe to verification.completed and verification.failed.

import exportflow

try:
    verification = client.verifications.create(shipment.id)
except exportflow.ConflictError as error:
    if error.code == "not_confirmed":
        ...                                   # ask the user to confirm the record
    raise

verification = client.verifications.wait(verification.id)
print(verification.severity_counts)           # a count for each severity found
for finding in verification.findings:
    print(finding.severity, finding.rule, finding.field, finding.message)

Each verification is pinned to the version of the rule set it ran against (rule_set_version), so a result can always be reconstructed. Running a new verification after the documents or the record change creates a new result; the earlier ones stay as they were. A shipment’s verifications are listed newest first.

Findings#

A finding is the outcome of one rule. It names the rule and its rule_version, the document_id and field it concerns when there is one, what was found and what was expected, and a message written for a person.

Finding severities
SeverityMeaningA pass?
criticalAn inconsistency that will cause rejection or refusal.No. Something is wrong.
verifyAn inconsistency that may be intentional. Evidence for a person to look at, not a conclusion.No. Somebody should check it.
cleanA rule ran, and it passed.Yes, for that rule.
uncoveredNo document-specific rule exists for this type of document. It was still cross-checked for agreement with the others.No. Nothing specific was checked.
unavailableThe check could not run because an input was missing, for example a field that could not be read.No. The check did not happen.
Uncovered and unavailable are not passes

Do not draw them in green, do not fold them into a count of passed checks, and do not hide them. A user who sees a tick beside a document nothing was checked against has been given an assurance nobody made. severity_counts gives the number of findings at each severity so you can show all five.

Severity values are lower case in responses. Compare them as written here, and treat a value you do not recognise as something to show rather than something to ignore: within version 1 a new value can be added.

Coverage#

Every verification carries a coverage declaration: a statement of what was checked and what was not, kept with the result. It is what makes a result honest when most of it is clean.

What the coverage declaration holds
FieldMeaning
rule_set_versionThe rule set the verification ran against.
rules_effective_onThe date the rules were applied as of, with effective_date_source saying where that date came from.
documentsOne entry for each document: its type, how many rules were applied to it (rules_applied), and validation, which is checked when document-specific rules ran or cross_checked_only when the document was only compared with the others.
fields_unavailableThe fields that could not be used, each with the reason and the document it belongs to.

The contract types coverage as an open object, so new information can be added to it within version 1. Show it beside the findings. A result presented without its coverage looks identical to a result that had nothing to declare, and that is the failure this API is built to avoid.

What ExportFlow checks, and what it does not, is published on the coverage page.