When custom SQL data quality tests in OpenMetadata fit your rules
Custom SQL tests fit when the built-in tests do not cover a business rule your data owners care about, such as an order total that must match a ledger balance, a customer status that cannot move backward, or a monthly revenue figure that must stay within an agreed range. The same rule often needs to run across many tables that share a structure, and writing a separate one-off check for each table produces drift, duplicate logic and tests nobody remembers to update. A reusable SQL test definition with parameters solves this in the OpenMetadata Test Library: you write the query once, declare the parameters it accepts, and then instantiate it against specific tables and columns with the values for each case. The rule lives in one reviewable place, and each test case records which asset and which parameter values it applies to.
Before you design definitions, confirm the exact syntax, the supported parameter types and the way test definitions are registered and referenced in the release you run. The OpenMetadata documentation for your version is the authority here, and this page does not assume a specific release. Check how the definition declares its entity type, how parameters are passed and validated, and whether a failing query is reported as a failed test or as an error. Also confirm which roles can register a definition and which can create test cases from it, because those permissions decide who can add new checks to production tables. DeployOpen plans and builds the definitions, the governance model and the rollout to your teams. We do not issue audit reports, attestations or certification results, so any evidence you present to an auditor must come from the independent assessor you engage.
Which test approach fits each data quality rule
This table compares four ways to express a data quality rule in OpenMetadata, from built-in Test Library tests to results pushed in from outside the catalog. Read each row for the kind of rule it suits, who usually maintains it, and what it costs in reuse versus review effort.
| Approach | Suits best | Usually maintained by | Main trade-off |
|---|---|---|---|
| Built-in Test Library test | Common checks such as nulls, uniqueness, ranges and row counts on one table | Data platform or catalog team | Fast to adopt, but limited to the test types the platform already provides |
| Reusable custom SQL test definition with parameters | Organization-specific business rules that apply to many tables with different thresholds | Data governance or domain analysts, reviewed by data engineers | Strong reuse across tables, but each definition needs SQL review and clear parameter documentation |
| Test case written against one table | A one-off rule tied to a single asset and owned by one team | The owning team of that table | Quick to create, but rules can drift and duplicate others when nobody reviews them centrally |
| Results pushed from an external tool or script | Rules that already run in other pipelines or quality frameworks | The team that owns the external pipeline | Keeps existing logic in place, but the test logic lives outside OpenMetadata and needs its own change control |
How a parameterized SQL test definition becomes a running check
A running SQL check in OpenMetadata is built from three layers, and knowing which layer holds what is the first step in designing reusable rules. A test definition holds the SQL logic and declares its parameters. A test case binds concrete values to those parameters for one specific table or column. The result is the outcome of each run, and failures surface on the asset page of the table or column the test case targets, where owners and downstream readers can see them. Before writing anything, confirm in the documentation for your release how custom SQL definitions declare their parameters, which parameter types are accepted, and how values are passed from a test case into the query. Parameter syntax and handling have changed between versions, so treat the release docs as the reference rather than examples from older posts.
Parameters are what make a definition reusable. One rule such as "the share of rows with a missing value stays below a threshold" can serve many tables and columns, each with its own threshold, without copying the SQL. The writer decides which parts are fixed logic and which parts are values a data owner should set. Keep the parameter list short and name each one for its meaning, so the test case form is understandable to someone who did not write the definition. Test a definition against a non-production copy of a table first, and check that a value outside the expected range fails in the way you intend, not with a query error that looks like a data problem.
OpenMetadata exposes REST APIs and a Python SDK for creating and reading test definitions, test cases and results programmatically, as described in the OpenMetadata GitHub project. Programmatic access matters when you need to create the same test case across dozens of tables or read results into your own reporting. Confirm the object names, field names and authentication method against the API reference for your version before building automation, since field names such as those used for parameter values are version-specific. Agree with your data owners in advance who may create a test case on their assets, because each test case you create through the API appears in the same catalog and alerting path as one created in the UI.
How definitions, test cases and results move through OpenMetadata
The flow starts with a data engineer or data owner drafting a custom SQL test definition with its parameters. A reviewer approves it, and a platform admin enables it in the Test Library so it can be used. Test cases then bind those parameters to specific tables and columns. On each scheduled run, the test executes against the warehouse, and results and failures return to the asset page and the owning team. Check that each hand-off has a named owner before you go live.
Custom SQL test flow from drafting and approval through scheduled runs to owners.
Setting up custom SQL data quality tests step by step
This sequence takes one organization-specific rule from a business owner's wording to a tested SQL definition bound to a pilot set of tables, with the owners reviewing results before wider rollout.
Inventory business rules and their owners
The data team, with the business owners of each dataset, lists the rules that built-in tests cannot express, such as a revenue column that must reconcile to a ledger total or a status code that must match a reference list. For each rule, record the table, the columns involved, the expected pass condition, the owner who accepts a failure, and the severity. Your data team or the business owners do this step, and DeployOpen can facilitate the workshop if you ask for it in the written scope. It is done when every candidate rule has a named owner and a plain-language pass condition that someone other than the author has confirmed.
Confirm version and Test Library behavior
Record the exact OpenMetadata version in each environment, then read the release notes for that version to confirm how custom SQL tests, their parameters and their enablement settings behave. Compare the version on your non-production copy with production, because a mismatch can change test behavior. The 2.0.0 release notes list breaking changes in the 2.0 line, and the upgrade steps in those notes apply if you are moving between major versions. Your platform team does this check, and DeployOpen can review it as part of the scope. It is done when the version and the relevant release-note sections are written into the change record.
Create a read-only database role for tests
Create a dedicated database role that can read only the schemas and tables named in the pilot scope, and grant no write, DDL or wildcard access. Confirm that the role cannot select from tables outside the pilot, and that the connection used by the test runner is the only place its credentials are stored. Your database team runs this step, and DeployOpen can provide the grant script and the review if you request it. It is done when a test query run with this role succeeds on pilot tables and fails with a permission error on a table outside the pilot.
Draft one parameterized test definition
Write the SQL for a single rule as a query that returns the rows that violate the rule, so zero rows means a pass. Replace the literal values you want to vary, such as a date window, a threshold or a status list, with parameters so the same definition works across tables. Document each parameter with its type and an allowed range. The data team writes the first draft, and the business owner signs off on the rule logic. It is done when the definition, its parameters and its description are saved in a version-controlled location and the author has written what a failing result means for the owner.
Validate the query on known bad data
Before the test touches real tables, run it against a non-production copy that you have seeded with rows you know should fail and rows you know should pass. Confirm that the query returns exactly the seeded violations and nothing else, and test the boundary values of each parameter. Repeat the check after any edit to the SQL. Your data team runs the seeded checks, and a second engineer reviews the expected results. It is done when the returned rows match the seeded expectations for every case, and the expected results are saved alongside the definition.
Bind the test to a pilot set of tables
Create test cases from the approved definition for a small set of tables, supplying the parameter values for each one, and leave enablement under the control of the people who approved the rule. Limit who can create and enable tests to named roles, and record which account made each binding. Check that the test appears on the correct asset pages and that the owner shown matches the owner in your inventory. Your data team performs the binding, and DeployOpen can help set the permissions model if the scope includes access governance. It is done when every pilot test is bound, enabled by an approved role, and visible on the right asset.
Run and review results with owners
Let the pilot run through several scheduled cycles, then review each result with the business owner: which failures were real defects, which were rule errors, and which were data that the rule should have allowed. Fix the definition or the parameters where the rule was wrong, and log the change with its reason. Decide with the owners whether to widen the pilot, and document the criteria. The data team leads the review, and DeployOpen can support the retest and the write-up. It is done when each pilot test has a recorded owner decision and the widening criteria are agreed in writing.
Who can create and enable custom SQL data quality tests
Data engineers draft most custom SQL test definitions. They know the table layouts, the load schedules and the joins that make a rule correct, so they are the people who turn a business rule into a parameterized query. Their work starts in a development or staging catalog and ends with a definition that other teams can reuse without editing the SQL.
- SQL correctness: Confirm the query returns rows only for failing records, handles nulls and time zones as the rule requires, and produces the same result when run twice on the same data.
- Query cost: Check the query plan and runtime on the largest table it will touch. Prefer filters on partition or clustering columns, and ask whether sampling is acceptable for the rule.
- Parameter defaults: Set defaults that are safe to run unattended. Avoid defaults that scan full history or that embed a value only one team would recognize.
- Naming conventions: Use a shared prefix or domain tag so definitions are easy to find, filter and retire. Describe the business rule in the description field, not the implementation.
Before a definition leaves the draft state, ask a second engineer to run it against a copy of production-shaped data and record the runtime. Confirm the exact permission names that allow creating test definitions in your OpenMetadata version, because they differ between releases and between how roles are assigned.
Data owners are accountable for what a rule means and how strict it should be. They decide whether a value of zero in a revenue column is a failure, what share of late records is tolerable, and which segments the business cares about. They do not need to read the SQL line by line, but they must confirm that the logic matches the policy they answer for.
- Business logic: Review the plain-language description and the expected result against documented definitions, not against what the data currently looks like.
- Thresholds: Agree the threshold values in writing and record who approved them and when. A threshold changed later should go through the same review.
- Scope of the asset: Confirm which tables and columns the test covers, especially where a rule applies to only one product line or region.
- Sign-off record: Keep the approval in the catalog or in a linked change record so auditors can trace why a rule fired or was silenced.
Owners often approve a rule that is technically sound but tests the wrong population. Ask the engineer to show a sample of rows the rule flags and a sample it passes before approving. Confirm with your platform team how owner assignment is reflected in the catalog so the approver is the person named on the asset.
Platform administrators control who can create, edit and enable tests in the shared catalog. They set the policy boundary, decide which connections a test can run against, and watch the load that scheduled tests place on production warehouses. Their decisions determine whether the catalog stays trusted as it grows.
- Roles and permissions: Map roles to the three actions of creating definitions, creating test cases and enabling scheduled runs. Use the policy engine's general controls, and confirm the exact permission names for your version before writing rules.
- Enablement control: Restrict who can switch a test on for a production schedule. Require a named approver for any test that runs on a large or regulated table.
- Run budgets: Set scheduling rules that stop many tests from running at the same moment against the same source.
- Audit trail: Confirm that changes to definitions and enablement are logged and that logs are retained for the period your policies require.
The trade-off is open authoring against central control. Open authoring finds rules faster but multiplies unreviewed queries, while central control protects the warehouse but can leave engineers waiting. Many teams allow broad drafting, restrict enablement, and review the permission model after the first quarter of use.
Security risks in custom SQL tests and how to contain them
A custom SQL test is code that runs against your warehouse with the credentials OpenMetadata holds, so it carries the same risks as any query job. The cards below cover privilege, data exposure, injection, change control, cost and credential storage, each with the control to apply before you enable a test.
SQL running with excess privilege
The test runs under the connection's database user, so a test author inherits whatever that user can read or write. Create a dedicated read-only role for the OpenMetadata connection, grant select only on the schemas the tests cover, and deny write and DDL rights. Before enabling a custom test, confirm in your warehouse's audit views which role executed it. Ask your DBA to verify the grant set rather than relying on the test's own WHERE clause to limit access.
Security docsSensitive values in failure samples
When a test fails, the failing rows or values can appear in the result, where users with catalog access may see them. A test that selects customer identifiers, national IDs or health fields can expose those values to people who never had warehouse access. Decide per column whether it may appear in samples, mask or aggregate it in the test, and check the classification tags on each referenced column before the test goes live. Document the decision in the test description so reviewers can check it.
Injection through test parameters
Parameters let one test definition serve many tables, but a parameter that is pasted into SQL text can change the query. Treat every parameter as untrusted input: restrict table and column names to an allowlist of identifiers, bind literal values rather than concatenating them, and reject free-form fragments. Test the definition with a hostile value such as a quote character or a trailing statement in a non-production environment. Confirm how your OpenMetadata version passes parameters before you allow authors to add new ones.
Definitions edited without review
A test definition that anyone can edit can change what it reads, when it runs or what it returns, and the change may go unnoticed until a dashboard shows a different result. Keep SQL definitions in version control, require a second reviewer for any change to the query or parameters, and limit who holds the permission to create and enable tests in OpenMetadata. Record who approved each definition so audit questions have an answer.
Warehouse cost from full scans
A custom query that scans a large fact table on every schedule can consume compute on a pay-per-scan or sized warehouse. Ask each test author for the partition or date filter the query uses, and set run frequency to match how fast the data changes. Review the scan size reported by your warehouse for the test's user before enabling it on a schedule. Costs recur every run, so a test that looks cheap once can become a standing expense.
Connection credentials stored in OpenMetadata
OpenMetadata needs database credentials to run tests, so the catalog becomes a place where warehouse secrets are held. Confirm how your deployment stores connection secrets, who can read or change them through the API and UI, and whether they can be supplied from an external secrets manager. Rotate the read-only credential on a schedule and check that rotation does not break scheduled tests. Review the authentication and trust model in the security docs before exposing the catalog to the wider company.
Trust model docsRunning and tuning custom SQL tests over time
The recurring work after go-live is keeping custom SQL tests tied to the business rule they were written for. Assign each test definition and each test case to a named owner, and schedule a regular review where that owner looks at failures, decides whether the data or the rule is wrong, and records the outcome. A failing test that nobody triages will train teams to ignore the whole suite, so treat an unexplained failure as a backlog item with a due owner rather than a permanent red result. Retire definitions when the rule changes, such as a new product code, a revised status list or a retired source system, and remove the matching test cases so the suite reflects current policy. Keep a short change log per definition so reviewers can see why a parameter or query changed.
Runtime is the cost that grows quietly. A query that scans a small table in pilot can take much longer once the table holds years of history, and custom SQL runs directly against your database, so the load lands on your warehouse or production replica. Measure execution time for each test after major data loads, add partition or date filters where the rule allows them, and confirm with your database team which schedule and which role the tests run under. Ask whether the tests should read from a replica or a warehouse copy, and set a threshold that triggers a review of the query design before it becomes a capacity problem.
Upgrades need their own check. The OpenMetadata 2.0 release notes list breaking changes that touch data quality, including the migration of Great Expectations to version 1.3, which the notes say should happen before upgrading. Before you upgrade, confirm whether any of your test definitions or ingestion images depend on Great Expectations, and run your existing custom SQL tests in a staging environment against the new release to compare results with production. Keep the release notes and your staging results with your change records, and assign one person to sign off on the upgrade for the data quality suite.
Limits to confirm before you commit to custom SQL tests
Custom SQL tests depend on details that vary by release, database and deployment, so none of these should be assumed. Each card names one item to check and where to confirm it, starting with what your staging environment can actually run.
SQL dialect and warehouse support
Confirm that your warehouses and database engines accept the SQL your test definitions use, including functions, quoting rules and date handling that differ between platforms. A definition that passes on PostgreSQL can fail or return different rows on another engine. Run each definition against every source it will cover, and check the connector documentation for the platform before writing shared definitions.
Deployment docsParameter typing and validation
Check how your release types, validates and escapes test parameters before you rely on them for values coming from users or other systems. Parameter handling changed between major releases, so confirm behavior on the exact version you run. Test a parameter with an unexpected type, an empty value and a value containing quotes to see what the platform does.
Sharing definitions across services
Find out whether a custom test definition created for one database service can be applied to tables in other services, and whether it needs to be recreated for each. Shared definitions reduce duplicate logic but can also spread a mistake into every service that uses it. Confirm the scope behavior in staging with two services before you publish a definition to the whole catalog.
Result and failure sample retention
Ask how long test results and failed row samples are stored, where they live, and whether retention can be set by your team. Failure samples can contain personal or confidential values, so retention affects your privacy and access obligations as well as storage. Confirm the default and the configuration key in your deployment docs, then verify that samples are not written where broader users can read them.
Permissions to create and enable tests
Map which roles can create test definitions, add test cases to a table, edit a running test and switch it on or off in your release. Permission names and defaults shift between releases, so review the security documentation and the release notes for your version. Test the permission matrix with a non-admin account in staging before you grant access to data owners.
Security docsBehavior on your own stack
Run a sample of your definitions on the ingestion schedule, database load and search configuration you will use in production. Custom SQL runs against your sources, so expensive queries can slow source systems and extend ingestion time. Measure run duration and source load on a production-sized table in staging, and confirm the runtime behavior with your database team before enabling schedules.
Common questions before hiring help with custom SQL tests
How much effort does a first set of custom SQL tests take?
The effort depends mostly on how many rules you need, how well each rule is understood by the business, and how many tables and columns the rules touch. A first set is usually small and focused on a few critical datasets, because each rule needs a written definition, an agreed threshold and a check that the query returns the expected result on real data. The main drivers are the number of parameters each definition needs, whether the same rule applies across many tables, and how much profiling you have already done. Ask any partner to break the estimate into definition design, testing against your data, review and handover, and to state which parts are one-time and which recur as rules change.
What do we need from our data owners before custom tests can be written?
Custom tests need an owner who can state the rule in business terms, such as what a valid order total or a complete customer record looks like, and who can confirm what a failure means. Owners also need to confirm which columns are authoritative, which dimensions matter, and what tolerance is acceptable before an alert is sent. Without these decisions, tests either fire constantly or pass without catching anything. Plan time for owners to review sample failing rows and to sign off the thresholds, because that review is usually the slowest dependency in the work.
Can our own team build custom test definitions without a partner?
Yes, if your team has SQL skills, access to the source databases through a read-only account, and someone who maintains the OpenMetadata deployment. The harder parts are not the SQL itself but agreeing on parameter names, setting a naming convention, reviewing definitions for performance on large tables, and deciding who may create or enable them. Many teams start in-house for a handful of rules and bring in outside help when they need a governed library across several domains. Whichever path you choose, check the current OpenMetadata documentation for the exact definition format in your version.
How long does a pilot usually run, and what sets its length?
A pilot's length is set by the number of data domains in scope, how quickly owners can review rules, and how much access your security team needs to approve before anyone can query production-like data. Environment readiness matters too: a working OpenMetadata instance, connected test data sources and a defined change process all add time if they are not in place. Agree the end point in writing before work starts, such as a defined set of tests passing against agreed datasets and a handover of the definitions. Ask for the schedule to show which steps depend on your people rather than on the implementation team.
How do custom tests hold up when we upgrade OpenMetadata?
Custom definitions can be affected by upgrades, so they should be version-controlled and listed in your upgrade test plan. OpenMetadata 2.0 introduced breaking changes, including a requirement to migrate Great Expectations to 1.3 before upgrading and a rebuild of custom ingestion images for Python 3.12, so check every dependency that touches test execution. Before upgrading a production instance, run your custom tests in a staging environment built from the same release and compare results with the current baseline. Confirm with your vendor or the release notes which definition fields changed in your target version.
What does DeployOpen deliver, and what stays with our team?
DeployOpen can plan and build the custom SQL test definitions, document their parameters, set up the access model for who may create and enable them, and test them against agreed datasets before handover. Your team keeps ownership of the business rules, the thresholds, the production access approvals and the ongoing review of new definitions. The written scope should name each deliverable, the environments it covers and the acceptance checks. Anything not listed, such as alert routing or incident workflows, should be confirmed as a separate item rather than assumed to be included.
How DeployOpen scopes and delivers custom SQL data quality tests
DeployOpen plans, builds and hands over custom SQL test definitions in OpenMetadata inside your own infrastructure, starting from the organization's rules and the tables they govern. Each engagement is agreed in writing before work starts, so owners, permissions and test coverage are settled before the first definition is written.
How we scope
- Inventory the business rules that need SQL tests and name the owning team for each rule.
- Agree in writing which tables, columns and parameters each reusable test definition will cover.
- Define who may create, edit and enable test definitions, and which roles approve them.
- Confirm the OpenMetadata version, database connectors and service accounts the tests will run through.
How we build
- Write parameterized SQL test definitions tested against representative data in a non-production environment.
- Check each definition for query cost, sampling behavior and how it handles nulls and late-arriving rows.
- Configure test cases and their parameters so owners can reuse one definition across many tables.
- Review permissions and enablement settings against the approval model agreed during scoping.
How we hand over
- Deliver a written catalog of test definitions, parameters, expected outcomes and owning teams.
- Document the create, review and enable procedure so changes follow the same path every time.
- Run a walkthrough with the data owners and platform team who will maintain the definitions.
- Provide the SQL, configuration and runbook as files your team controls in its own repository.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer after handover.
- Re-verify test definitions when OpenMetadata releases change test behavior or breaking changes apply to your version.
- Confirm the scope, deliverables and timeline for any change request in writing before work starts.
- Ask for a written quote based on the agreed scope, since DeployOpen does not publish a price list.

