Skip to main content
Version: v3

Learn Data Hooks®

After finishing this guide, you will have a deep understanding of Data Hooks® and how to leverage them for data validation.

What are Data Hooks®?


If you are configuring Data Hooks in code with the Platform SDK, then please refer to this guide on Data Hooks® in code

Data Hooks® are one of Flatfile’s most powerful data validation tools. Data Hooks are short sections of JavaScript that can re-format, correct, validate, and enrich data automatically during a data import.

Did you know?

Data Hooks® are a registered trademark of Flatfile Inc. 🙌

Start using Data Hooks®

Data Hooks® are associated with specific templates, and can be added and modified from your Flatfile dashboard. Check out this Knowledge Base article for more information on how to add Data Hooks® to a template.

How Data Hooks® work

Data Hooks® are attached to specific data templates, and each data template may have as many Data Hooks® as you need.

When you upload a file, all Data Hooks® active on that template will run in parallel, at least once. It is possible (though not guaranteed) that a hook may run more than once.

Example Data Hooks®

* Helper function to determine if a value is null or undefined.
* Useful in if/else statements or ternaries.
* @param {*} val - Any object/value
const isNil = (val) => val === null || val === undefined || val === "";

* Helper function to determine if a value is NOT null or undefined.
* Useful in if/else statements or ternaries.
* @param {*} val - Any object/value
const isNotNil = (val) => !isNil(val);

module.exports = ({ recordBatch, _session, _logger }) => {
return => {
const { email, phone } = record.value;

if (isNil(email) && isNil(phone)) {
record.addWarning(["email", "phone"], "Must have either phone or email");

Logging with Data Hooks®


This feature is still in beta. Please reach out to if you would like logging enabled for your account.

You can also choose to insert your own logging statements within the Data Hook® code. This is useful for testing and debugging, as well as monitoring when something codes wrong.

  •"your message here"): adds an information-level log message when executed
  • logger.warn("your message here"): adds a warning-level log message when executed
  • logger.error("your message here"): adds an error-level log message when executed

To review logs, navigate to the Logs section of the Flatfile dashboard, where you can see each event (import) that triggered a Data Hook®. Logs contain your own logging messages as well as system-level information that indicate the result of any attempted Data Hook® execution.

Up next

Please refer to Data Hooks® in code