Q&A library Survey design

How do I build validation into an ODK or Kobo form so errors are caught at entry?

Survey design Intermediate data qualitykoboodk

Short answer

Use constraint and required in the XLSForm. A value rejected on the enumerator's phone costs seconds. The same value discovered during cleaning costs a callback, or a wrong number in a report.

The short version

Validation belongs at the point of entry, not the point of analysis. In an XLSForm, three columns do most of the work: required, constraint, and constraint_message.

The survey sheet

type name label required constraint constraint_message
integer age Age of respondent yes . >= 0 and . <= 120 Age must be between 0 and 120
integer children Children in household yes . >= 0 and . <= 25 Please confirm, this is unusually high
date interview_date Date of interview yes . <= today() The interview cannot be in the future
select_one yes_no enrolled Is the child enrolled? yes

The dot refers to the answer being given. today() is evaluated on the device.

Constraints that reference another question

This is where most real errors live. A child cannot be enrolled in a school year before they were born.

constraint: ${enrolment_year} >= ${birth_year}
constraint_message: Enrolment year cannot be before the year of birth

And a follow up question that should never appear for the wrong respondent:

relevant: ${enrolled} = 'yes'

An irrelevant question is not merely hidden. It is never asked, never stored, and never needs cleaning.

Soft warnings versus hard stops

A hard constraint that is occasionally wrong will teach enumerators to enter a false value to escape it. If 25 children is possible but rare, do not forbid it. Ask for confirmation instead: make it a separate select_one that says "you entered 25 children, please confirm".

Rule of thumb: hard stop only on the impossible, confirm on the implausible. An enumerator standing in a compound at dusk will find a way past any constraint you set on the merely unlikely, and the way they find will be a lie.

Test the skip logic before deployment, not after

Every branch, on a real device, with a person who did not build the form. A skip rule that fires wrongly silently removes a question from thousands of interviews, and you find out at analysis, when the column is empty and the fieldwork is over.

What this buys you

On a nationwide survey across all 37 states, entry level validation is the difference between a dataset that arrives at 95 percent accuracy and a cleaning exercise that runs for months and still leaves you defending a figure you do not fully trust.

Cleaning cannot recover information that was never collected correctly. It can only decide what to do about the damage.

Need this solved on your own data?

The library is free and always will be. When the problem is bigger than an answer, we take on the work.

Start a project