Back to Glossary Index


Check data for completeness, accuracy, and consistency.

Data validation definition:

Data validation is a critical step in the data engineering process to have trusted, complete data. Data validation can be performed at various stages, including during data ingestion, transformation, and loading.

The following are some best practices for data validation in the context of modern data pipelines:

  • Define clear validation rules: It is essential to define clear validation rules to ensure that the data is validated correctly. These rules should be based on the data requirements, such as data type, format, and constraints.
  • Validate data as early as possible: Data validation should be performed as early as possible in the data pipeline to detect errors as soon as possible. This approach can save time and resources by preventing the propagation of errors.
  • Use automated validation: Automated validation can help ensure that the data is validated consistently and accurately. Automation can include using tools, scripts, or frameworks that check the data against predefined validation rules.
  • Monitor data quality: Monitoring data quality is an ongoing process that involves tracking the data quality over time. This approach can help detect data quality issues early and take corrective actions.

Data validation example using Python:

Please note that you need to have the necessary Python libraries installed in your Python environment to run this code.

Python provides several libraries and functions for data validation. Let's look at three of them:

Pydantic: Pydantic is a data validation library that provides runtime type checking and validation of data structures. Dagster uses Pydantic internally to validate data for configuration or resources, for example. Here’s an example of Pydantic in action:

from pydantic import BaseModel

class User(BaseModel):
    id: int
    name: str
    email: str
    age: int

user_data = {"id": 1, "name": "John Doe", "email": "", "age": 30}
user = User(**user_data)

This will output:

id=1 name='John Doe' email='' age=30

Cerberus: Cerberus is a lightweight and extensible data validation library that can validate complex data structures. Let’s look at an example of Cerberus in action:

from cerberus import Validator

schema = {"name": {"type": "string"}, "age": {"type": "integer", "min": 18}}

data = {"name": "John Doe", "age": 25}

v = Validator(schema)
if v.validate(data):
    print("Data is valid")
    print("Data is invalid")

Output yielded by v.errors:

Data is valid

Great Expectations: Great Expectations is a data validation library that can validate data quality and test data pipelines. It provides a range of features, including automated data profiling, data documentation, and testing data pipelines.

Here’s an example:

We can train Great Expecatations on a small data sample ( small_dataset.csv ), then apply the learnt rules to our large dataset ( large_dataset.csv ). The Small and Large datasets can be anything youlike, but should have a list of unique ids inthe id column:

You can use a sample as follows for the large dataset, and use just the first 10 rows in your small dataset.

id,Col A,Col B,Col C,Col D,Col E,Col F,Col G,Col H,Col I,Col J,Col K,Col L,Col M

And apply this code to it:

import great_expectations as ge

# Build up expectations on a representative sample of data and save them to disk
train = ge.read_csv("small_dataset.csv")

# Load in a new batch of data and test it against our expectations
test = ge.read_csv("large_dataset.csv")
validation_results = test.validate(expectation_suite="my_expectations.json")

# Take action based on the results
if validation_results["success"]:
    print ("The validation passed")
    raise Exception("The validation failed")

This will output:

The validation passed

So what is going on here?

  1. We import the Great Expectations library
  2. We use the `ge.read_csv()`` method to read in a CSV file containing a representative sample of data. In this case, the CSV file is named large_dataset.csv.
  3. We then use the `expect_column_values_to_not_be_null()`` method to build an expectation that the "id" column in the data should not contain null values.
  4. After building up our expectations, we use the save_expectation_suite() method to save them to disk in a JSON format. The resulting expectation suite is saved to a file named my_expectations.json .
  5. Load in a new batch of data using the ge.read_csv() method, again reading from the large_dataset.csv file.
  6. Use the validate() method to test the new data against our expectations. The expectation_suite parameter specifies the name of the JSON file containing our expectations.
  7. The validate() method returns a dictionary of validation results. We check the "success" key of this dictionary to see if the validation passed or failed. If it passed, we print a message indicating that the validation was successful. If it failed, we raise an exception with a message indicating that the validation failed:
Traceback (most recent call last):
  File "/Users/myname/", line 16, in <module>
    raise Exception("The validation failed")
Exception: The validation failed

Other data engineering terms related to
Data Management:


Move rarely accessed data to a low-cost, long-term storage solution to reduce costs. store data for long-term retention and compliance.


Add new data or information to an existing dataset to enhance its value. Enhance data with additional information or attributes to enrich analysis and reporting.


Create a copy of data to protect against loss or corruption.


Select, organize and annotate data to make it more useful for analysis and modeling.


Identify and remove duplicate records or entries to improve data quality.


Analyzing the number of features or attributes in the data to improve performance.


Enhance data with additional information from external sources.


Extract data from a system for use in another system or application.


Create an optimized data structure for fast search and retrieval.


combine data from different sources to create a unified view for analysis or reporting.


Store the results of expensive function calls and reusing them when the same inputs occur again.


Combine data from multiple datasets into a single dataset.


Extract useful information, patterns or insights from large volumes of data using statistics and machine learning.


Create a conceptual representation of data objects.


Track data processing metrics and system health to ensure high availability and performance.

Named Entity Recognition

Locate and classify named entities in text into pre-defined categories.


Interpret and convert data from one format to another.


Divide data into smaller subsets for improved performance.


Transform your data so it is fit-for-purpose.


Transform raw data before data analysis or machine learning modeling.


Create a copy of data for redundancy or distributed processing.


Increasing the capacity or performance of a system to handle more data or traffic.

Schema Mapping

Translate data from one schema or structure to another to facilitate data integration.


Ensure that data in different systems or databases are in sync and up-to-date.


Maintain a history of changes to data for auditing and tracking purposes.