Required fields and custom validators in CKAN dataset forms

CKAN required fields and custom validators decide what metadata a dataset form will accept. This page explains the options, setup sequence, draft behavior on CKAN 2.12, and the points to confirm before you rely on them.

On this page

CKAN required fields and custom validators: enforcing metadata at entry

Validators run when a dataset is created or edited, and they decide which values the portal accepts before anything is saved. A portal team needs them when incomplete or inconsistent metadata reaches the catalog and causes problems later: a dataset published without a license or contact point, a publisher name typed three different ways, or a theme entered as Env in one dataset and Environment in another. Three situations usually justify the work: publishing rules the organization has written down and must enforce, pick lists that must stay consistent for search and reporting, and DCAT output that must map cleanly when ckanext-dcat converts datasets to RDF. Decide these rules before writing any code, because each one becomes a rejection that a data publisher will see.

Split the work between two places. The schema file controls the fields: their names, labels, presets, and the required settings and validators attached to each one. These cover most publishing rules and need no Python, since ckanext-scheming reads them from a YAML file. Extension code controls what a schema cannot express, such as a check that compares two fields, a lookup against an external list, or a rule that depends on the organization a user belongs to. Custom validator functions live in a plugin that implements CKAN's validator interface, and the schema names them so the form calls them. Ask your developers which validators already exist in the ckanext-scheming version you plan to install, and confirm that version before you write new ones.

Test every rule with records your publishers actually produce. Prepare a set of sample datasets that should pass and a set that should fail, then submit them through the web form and the API. Check that each error message tells the publisher which field to fix and why. Confirm with a test whether a new required field blocks edits to datasets already in the catalog, because that depends on how the rule is written and on what your team changes. Also confirm whether API calls run through the same validators as the form, since a rule that only the form enforces leaves a gap. Record an owner for each rule, because the person who changes a pick list later needs to know which exports and harvests depend on it.

Which validator fits each metadata rule

This table compares the validator types and ordering rules used to enforce metadata quality when a dataset is entered. Read each row for when the check runs, what it protects and the kind of field it suits. Confirm every identifier against the ckanext-scheming documentation for your CKAN version before you write a schema, because validator names and behavior can change between releases.

Validator or ruleWhen it runsWhat it protectsWhen it fits
scheming_requiredOn create and update, for fields marked required in the schemaBlank values in fields every dataset must completeCore fields such as title, license and publisher contact
Presence checks (not_empty, ignore_missing)On create and update, in the order listed for each fieldEmpty or absent input before later checks runBaseline for optional and required fields alike; confirm which fits each field
Validator orderingLeft to right, as written in the field's validators settingWhether cleanup runs before a required or format checkAny field that needs trimming, conversion or a check in sequence
Create-only validatorsRuns when a dataset is first created and is skipped on later editsIdentifiers or source references that must stay fixed after entrySet-once values; confirm the approach for your CKAN version
Output validatorsWhen the stored value is read back through the form or APIConsistent presentation of stored values, without changing what is savedDisplay formatting of stored codes or dates; confirm the key name for your version
Custom validator functionsOn every create or update that names the validator in its schemaRules that built-in checks cannot express, such as cross-field consistencyLogic tied to your data model; write unit tests and register it in a plugin

Every dataset write passes validators before storage and again on read

The diagram starts at a form submit or an API write and passes the entry through the field validators in the order the schema lists them. A failed check ends the path at an error returned to the user, so nothing is stored. An accepted entry moves to the create or update branch, then into storage. A draft dataset takes its own branch to storage, so confirm which required-field checks apply to drafts on your CKAN version before you rely on them. When the API or a downstream output reads the dataset, output validators run again on the way out. Review the field order in the schema and test both paths before go-live.

Path of a dataset write through validators, storage and read-side outputs.

How validator order decides which error the user sees

Validators on one field run in the order they appear in its chain, and the first check that fails stops the chain. The user sees only that message, so position decides two things at once: which problem the contributor hears about first, and which rule is enforced first. In a ckanext-scheming field definition, the validators are set as a sequence on the field, and the scheming_required setting adds a required check to the field's rules. Confirm where that required check sits relative to your format and length checks in the version your portal runs, because that position is what the contributor experiences. Treat the order as a design decision that the schema owner records for every required field.

The example below is illustrative and uses a hypothetical contact_email field. Suppose the format check runs before the required check, and the format check rejects empty input. A contributor who leaves the field blank then sees a message saying the email address is invalid. The person reads that as a typing mistake, retypes an address, and the required rule never gets to explain the actual gap. Reversing the two checks shows the required message first for a blank field, but a malformed address then passes the required check and reaches the format check. Each order favors a different failure, so choose the one that matches how your contributors make mistakes, and test both paths.

Before release, test each required field with three inputs: blank, malformed, and valid. Record the message the form shows for each, and check the error the API returns for the same input, since both come from the same validation chain and a dataset can be created through either path. Ask the schema owner to keep the intended validator order beside each field in version control, so that a later edit which moves a check is visible in review. Finally, confirm the ordering behavior in the ckanext-scheming version your portal runs, and repeat the test after any extension upgrade, because the order a field produces is only as stable as the version that enforces it.

Setting up required fields and a custom validator in an extension

This sequence adds required fields and one custom validator to a CKAN dataset form through a schema file and a small extension, so the rules live in version control and move between environments with the rest of the code. Each step closes with a check you can run on a staging instance before anything reaches production. The result is a form and API that reject incomplete or malformed entries in the same way.

  1. Confirm CKAN and ckanext-scheming versions

    Record the CKAN version your portal runs and the ckanext-scheming release that supports it, using the compatibility notes in each project's documentation. CKAN 2.12.0 was released on August 26, 2026, so confirm that your scheming release supports the minor version you plan to run before writing any code. Pin both versions in the requirements and deployment files. Done when a staging instance reports the same versions as production and the pinned values are committed to the repository, because every later check depends on them.

  2. Define schema fields and required flags

    Write the dataset fields in a ckanext-scheming schema file, one entry per field, with a label, a field type and a required flag for each field your metadata policy makes mandatory. Keep the file in the extension repository so every environment loads the same definition. Agree with your data governance owner which fields are mandatory at publication and which are optional, since that choice drives every later test. Confirm how your scheming version applies required checks to draft datasets in its documentation. Done when the schema loads without errors on staging and the form labels each mandatory field.

  3. Write the custom validator function

    Write a Python function that receives the field value and CKAN's validation context, then either returns the cleaned value or raises a validation error with a message a publisher can act on. Follow the argument signature your scheming version expects. Keep the rule narrow, such as a pattern check on an identifier or a condition across two fields, and write down what it accepts. Place the function in the extension's package so it ships with the schema. Check it with unit tests covering one passing value, one failing value and one empty value, and confirm all three behave as written before connecting it to the form.

  4. Register the validator with the plugin interface

    Declare that your plugin class implements the validators interface, then return a dictionary from the get_validators method that maps a validator name to your function. Add the plugin to the plugins setting in the staging configuration and restart the web and worker processes so the change loads. Done when CKAN starts without errors on staging and the validator name can be resolved by the schema. If the name is not found, check the plugin order and the spelling of the dictionary key before changing the function.

  5. Reference the validator from the schema

    Add the validator name to the validators key of the target field in the schema file, and keep the required setting on that same field so both rules apply. When several validators run on one field, confirm the order your scheming version applies them, and check the documentation for where the required check runs in that order. Reload the schema on staging and confirm it loads without errors. Done when the field shows its required marker and an invalid value is flagged in the form, matching the unit test results from the previous step.

  6. Test create and update in the web form

    Sign in to staging as a publisher with edit rights in one organization and run three entries against the new dataset form: a complete entry with a valid custom value, an entry that leaves a required field empty, and an entry with a value the validator should reject. The first should save, and the other two should show an inline error on the correct field. Repeat the same three cases on the edit form of an existing dataset, and on a draft if your portal uses drafts. Done when the rejected entries keep the other input the publisher typed and the saved dataset shows the expected values.

  7. Test the API create and update paths

    Send the same three cases through the CKAN action API with an API token from a test account, using package_create for new datasets and package_update for existing ones. Confirm that rejected payloads return an error that names the offending field and that accepted payloads return success. Fetch each accepted dataset with package_show and compare the returned fields against the schema file, so you can see that the stored output matches the definition. Done when every schema field you expect appears in the response with the value you sent, and the request and response pairs are saved for the evidence file.

  8. Record evidence and promote the change

    Save the schema, plugin code, unit test results, request and response examples and version pins in the repository, then promote the same commit to production through your normal change process. Run a short production check by creating one test dataset in a non-public organization, confirming the validation messages match staging, and deleting the dataset afterward. Confirm the deletion path and your retention rules with your portal team before the check. Done when the production results match the staging record and the evidence is linked from the change ticket.

Writing custom validator functions in an extension

A custom validator is a Python function that receives the value entered for one field and either returns a cleaned value or raises a plain error message using Invalid, the exception CKAN's toolkit provides for validation failures. The exact arguments depend on where the validator is called, since a field-level validator and a whole-dataset validator are invoked differently, so confirm the call signature in the CKAN version you run before writing code. The message is what the person filling in the form reads, so it should name the field and state the rule, such as the allowed date range or the expected identifier format. Keep the function free of side effects where you can. A validator that runs on every save and changes other fields or queries the database is much harder to debug when a dataset fails to save.

Packaging is what lets the schema refer to the function by name. In your extension, create a plugin that implements the IValidators interface and has its get_validators method return a dictionary that maps each name to its function. Add the plugin to ckan.plugins in the portal configuration, then use the same name in the field's validator list in the schema. The name is the only link between the two files, so a misspelled name is a configuration error that a test loading the schema should catch. Keep the plugin in version control next to the schema, and record which CKAN minor version it was written for. Minor releases may include backwards-incompatible changes, as the CKAN release policy explains, so check the plugin interface against your version before you write code.

Choose between a short check in the schema and a shared function in an extension based on who else needs the rule. A short check that uses validators CKAN already provides keeps the rule beside the field it governs, which suits a rule only this portal needs. A shared function costs more to set up: you write a plugin, add tests, package it, deploy it to each environment and keep it working through every CKAN upgrade. It pays back when several portals or dataset types need the same rule, such as one identifier format across a national catalog, because a fix then reaches all of them at once. Before you build it, ask who will maintain the extension after handover and how often the rule is likely to change. Schema and code must move together, so confirm your deployment process updates both in the same release.

Draft datasets on CKAN 2.12 and when required checks apply

A draft is a dataset saved before it is complete. Contributors can save a dataset in draft state and return to it later, and drafts are not meant to appear as published records. The key question for this tab is whether a required field stops that save at all. If it does, contributors may be blocked from saving unfinished work. If it never does, the field gives no protection until the record is published, so the team needs to know which behavior applies to its schema.

  • When checks run: Confirm whether scheming_required is evaluated when a draft is saved, or only when the dataset moves to the active state.
  • What the user sees: Note the message a contributor receives when a required field is empty, and whether the draft still saves with that field blank.
  • Search and listing: Confirm that drafts stay out of public search, organization pages and group listings in your theme.
  • Extension version: Record the ckanext-scheming version in use, because validator behavior for draft state depends on the extension release as well as on CKAN itself.

Check these behaviors with a test draft on a staging portal before you write contributor guidance.

Security and operational risks of validation in the form

Validation in a CKAN dataset form protects metadata only when it holds across every way a record can enter or change, and across every upgrade. The risks below share one question: does a rule still hold outside the form, after code changes, and after an upgrade? Work through them before go-live and again before each CKAN upgrade.

Validators that skip API writes

A required field that is enforced only in the web form can be skipped by any script or client that calls the action API directly. Each rule must be attached to the schema field that the API also uses, so confirm this for every rule rather than assuming it. Create test datasets through package_create and package_update with missing and malformed values, then confirm each one is rejected. Repeat this check after every schema or extension change.

Who can change schemas and code

Anyone who can edit the scheming file or the Python validator functions in an extension can remove a required flag or swap a strict validator for a permissive one. A one-line diff can change what every future entry must pass. Limit write access to the schema and extension repositories, require review for any validator change, and audit who holds sysadmin rights, since those accounts can change configuration and data outside the form.

Error messages that expose internals

Validation messages appear to whoever submits the form, which may include public or partner accounts. A message that names internal field keys, schema paths or Python exceptions can reveal how the portal is built. A message that echoes the rejected value can repeat personal data on screen or in a cached page. Read every message with a non-sysadmin account, and write messages in plain language that uses the field label users see.

Logs that keep rejected entries

Rejected submissions can end up in application logs, web server access logs or error traces, depending on log level and how errors are raised. Those records may hold personal data or sensitive values that the form was meant to refuse. Ask the operations team which logs capture request bodies, set retention for each one, and restrict who can read them. To test, submit a deliberately invalid value containing a unique string and search the logs for it.

Regression after minor upgrades

CKAN patch releases avoid backwards-incompatible changes and schema changes, but minor releases may include backwards-incompatible changes. A validator that behaves correctly on one minor version can accept, reject or reformat values differently after an upgrade. Pin extension versions, run your validation test cases on a staging copy before each minor upgrade, and read the release notes for changes to validation or the dataset form. Run the same checks after patch releases too, because your own extensions can still break.

CKAN release policy

What buyers ask before adding validators to a CKAN portal

How much does it cost to add validators to a CKAN dataset form?

Cost follows from the written scope, because DeployOpen does not publish a price list. Four things drive it: the number of rules, whether each rule can use a standard check or needs custom Python code in an extension, how much automated test coverage you require, and how many installed extensions must keep working alongside the new code. Build and testing are typically one-time costs. Keeping validators working through CKAN upgrades and schema changes is the recurring cost. When you request a quote, ask for each rule listed separately, the test approach for each, who owns the extension repository after handover, and which items are excluded.

How long does it take to add custom validators to CKAN?

Duration follows the same drivers as cost, so no fixed timeline applies across projects. A small set of required fields on an existing schema is a short task. Custom validator functions that cross-check fields, call external services or sit inside a new extension take longer, because they need design, tests and review on a staging portal. Timing also depends on how quickly data owners settle the field rules and on your change approval process. Ask for the timeline as milestones in the written scope: rule inventory, staging build, test sign-off and production release, with the client's responsibilities listed against each milestone.

What does the client need to provide for validator work?

The client supplies decisions, a matching staging environment and access to the code. The main inputs are:

  • A rule list agreed by the data owners, with the allowed values and the reason for each rule.
  • A staging CKAN instance on the same version as production, with the same installed extensions and configuration.
  • Access to the schema file, the extension repository and the deployment pipeline.
  • A named person who can settle disputed rules quickly.

Without these, the work stalls while the team waits for decisions, and the code itself is rarely the bottleneck.

Can our internal team add CKAN validators without a partner?

Yes, a team with Python and CKAN extension experience can do the work alone, and many do. The skills involved are writing validator functions, attaching them to a ckanext-scheming schema, writing tests against a running CKAN instance and reviewing changes before each upgrade. Check three things first: whether someone on the team has built a CKAN extension before, whether a staging environment exists, and whether a named person will own the code after the first release. Teams missing one of these often find that testing and upgrade work take more effort than the initial rules.

Will CKAN upgrades break our custom validators?

Upgrades can break validators, and the risk depends on the type of release. CKAN patch releases are meant not to break backwards compatibility and exclude schema changes and new features, while minor releases may include backwards-incompatible changes. Validators that rely on CKAN internals or on a specific extension version are the most exposed, so each upgrade needs the validator test suite run against the target version. Read the CKAN release policy before planning, and check the notes for CKAN 2.12.0, released on August 26, 2026, for changes that affect validation. Ask any partner to include validator retesting in each upgrade's written scope.

Does CKAN validation apply to bulk imports and harvested datasets?

Only import paths that run through the CKAN action API are reliably checked, so confirm each path before you depend on it. Validators in a schema run when a dataset is created or updated through that API. Bulk loads that write directly to the database, or that skip the API, may bypass them. Test each path with one deliberately invalid record: any import script, any harvester, scripted API calls and any direct database work. Also confirm how existing records are handled when a field becomes required, because older datasets may not be checked until someone edits them.

What to confirm in your environment before you rely on validators

Validators only protect metadata if they behave the same way on every CKAN version, extension version and write path you run. The five checks below cover where those assumptions tend to break, and each one names where to confirm it before you depend on a required field.

ckanext-scheming against your CKAN version

ckanext-scheming reads your schema file and applies scheming_required and the validator chain inside CKAN's dataset form, so its release must match the CKAN minor version you run. Compare the version pinned in your requirements file with the CKAN version on your staging host, and check the extension's release notes for the supported CKAN range. Run pip show ckanext-scheming on that host, then load a schema with one required field and confirm the form rejects an empty value before you upgrade production.

Draft dataset handling on CKAN 2.12

CKAN 2.12.0 was released on August 26, 2026, and a draft dataset is saved before it is complete, so the point at which your validators run matters. Confirm whether required fields are enforced when a draft is saved, when it is published, or both. Compare the same schema on your current version and on 2.12 in staging, and read the 2.12.0 notes in the CKAN releases list for changes to draft handling.

API and harvest write paths

Validators that protect the web form may not cover every write path. Create a staging dataset through the package API with a required field missing, then run a harvest job from a source that omits the same field. Record which writes are rejected, which are stored with errors, and where the error message lands, since a harvester may log a failure and continue with the next record. Your findings decide whether the web form is the only control or one of several.

Multilingual and DCAT mappings

A required field that is translated per language or mapped to a DCAT property can pass validation on one path and fail on another. Use the sibling topics on multilingual metadata and DCAT-AP 3 mapping as your test plan, and check how language keys and the ckanext-dcat output interact with each validator. Export one test dataset to RDF through the DCAT endpoint, then confirm each required property appears with the language tags you expect.

ckanext-dcat repository

Your patch and minor upgrade policy

CKAN targets about two minor releases a year and supports the latest patch of the current minor version plus the previous minor version. Patch releases are meant not to break backwards compatibility, but minor releases may include backwards-incompatible changes, so a validator that works today can fail after a minor upgrade. Confirm in your own change policy who approves a minor upgrade, how long a patch may wait, and whether staging runs the same extension versions as production before any release reaches users.

CKAN release policy

How DeployOpen scopes and delivers validator work for CKAN

DeployOpen treats required fields and custom validators as part of your metadata design, agreed before any code is written. We scope the rules against your dataset schema, build them in a version-controlled extension, and test them on a staging portal before release. Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.

How we scope

  • Inventory every field that must be present, and which ones only apply on publish or in draft.
  • Agree in writing which validators run on create, which run on every save, and which run on output.
  • The written scope names the dataset types and CKAN version covered, including draft handling on CKAN 2.12.

How we build

  • Write custom validator functions in a dedicated extension, with unit tests for valid, empty and malformed input.
  • Check the order of required-field and validator chains so errors attach to the correct field.
  • Test each rule through the web form and the API, then confirm the behavior on your CKAN version.

How we hand over

  • Deliver the schema file, validator code and test suite in version control, with a short change log.
  • Document each rule with its field, trigger point, error text and the reason it exists.
  • Run a walkthrough with your data stewards so they can test edge cases before go-live.

How we support

  • Ongoing support is available as a retainer, covering rule reviews after schema changes.
  • Validators can break on CKAN upgrades, so each upgrade includes a retest of the rules.
  • Confirm the CKAN and extension versions your portal runs before requesting a quote.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.