数据契约
原题Data Contracts
读前速览
本文介绍了数据契约:一种机器可读、可验证且带有版本控制的协议,用于定义数据模式、质量规则、SLA 和使用条款,从而为人工分析师和 AI 智能体提供可信的数据处理机制。
数据契约是机器可读、可验证且带有版本控制的 YAML 文档,用于定义数据模式、质量规则、SLA 和使用条款。
这些契约让人工分析师和 AI 智能体无需手动解读或协商,就能了解数据结构、质量保证和允许的用途。
AI 智能体需要明确的数据契约,因为它们会将每个值视为事实,而不像人类那样会质疑不确定的数据。
如果没有契约,智能体可能会在数据不完整或被误解时,生成看似笃定、实则错误的结果,破坏数据生产者与使用者之间的信任循环。
Open Data Contract Standard(ODCS)是定义数据契约的事实行业标准,拥有相应工具和验证模式的支持。
ODCS 提供结构化的 YAML 格式,包含数据模式、质量规则、SLA、所有权和 AI 上下文等部分,从而支持自动验证并与数据市场集成。
数据契约包含可自动验证的质量规则和 SLA,以确保数据的新鲜度、完整性和准确性。
例如,可以通过基于 SQL 的质量检查验证行数或空值百分比;SLA 则规定数据新鲜度保证(例如,数据须在 24 hours 内更新),并对其进行持续测试。
AI 上下文部分为智能体提供专门指导,包括操作说明、约束和经过验证的陈述,以防止误用并提高准确性。
这类指导会告诉智能体如何解读数据(例如,保费以分为单位存储)、哪些操作不得执行(例如,不能针对个别客户做出决策),并提供针对常见业务问题的预验证查询。
完整摘要
本文介绍了数据契约这一构建可信数据驱动系统的基础机制,尤其是在智能体 AI 时代。文章说明,数据契约是机器可读的 YAML 文档,用于描述数据模式、质量规则、服务等级协议、所有权、使用条款以及面向 AI 的上下文信息。文章以 Open Data Contract Standard(ODCS)作为事实上的行业标准,展示了提供方如何发布单边契约,帮助数据使用者回答关键问题:数据模式的结构如何、数据是否足够新鲜、质量有何保证、数据在法律上可如何使用,以及有哪些访问控制。文章强调,AI 智能体会将数据视为事实,因此必须通过明确的契约来避免产生看似笃定、实则错误的结果。文章还详细介绍了数据契约的关键特征:机器可读、可验证、带有版本控制、由提供方驱动但以使用者为中心,并作为元数据的事实来源。文章也探讨了所有权与支持渠道、使用条款、关于数据新鲜度和保留期限的 SLA、数据位置规范、角色与安全、用于指导智能体的 AI 上下文,以及定价考量等实际内容。
目录 · 37 节
我们为什么需要数据契约Why We Need Data Contracts
随着当今智能体式人工智能的兴起,易于发现和处理的业务数据已成为任何公司迈向数据驱动型企业的基石。在大型企业中,这些宝贵的数据产生于公司内部的各个地方,而不同团队最了解各自特定领域的情况。因此,构建有价值的分析或数据应用,通常需要汇集来自各种来源的数据,并将它们有意义地关联起来。在整合多方数据的过程中,数据可信度成为一个至关重要的因素。With today's rise of agentic AI, well-discoverable and processable business data has become the cornerstone of any company's journey towards a data-driven business. In large companies, this valuable data is created at various places within the company, with different teams being most knowledgeable about a particular topic. Therefore, creating valuable analytics or data applications is usually about pulling data together from various sources to connect them meaningfully. In this process of combining data from many sources, trust in the data becomes a major factor.
设想一下,Alex 是一家跨国保险公司的数据工程师,正在构建一款客户洞察应用,用于预测客户购买额外保险产品的可能性。在公司的数据仓库中,Alex 找到一个数据集,其中似乎包含了进行这项预测所需的大部分信息,但 Alex 还有几个问题:Imagine Alex, a data engineer at a multinational insurance company, building a customer insights application that predicts the likelihood of customers buying additional insurance products. In the company's data warehouse, Alex found a dataset that seems to contain most of the information needed to make this prediction, but Alex has several questions:
- 数据集是否包含我需要的所有信息?这些信息以什么形式呈现?Does the dataset have all the information I need and in what form?
- 这些数据是否包含我认为它们包含的信息,并具有我认为的含义?Does the data contain the information and have the meaning that I think it does?
- 它是否与其他数据集相连接?如果是,连接了哪些数据集?Is it connected to other datasets? If so, which?
- 数据有多新、多完整,质量如何?How fresh and complete is the data, and of what quality?
- 我能否依赖其结构保持稳定,从而确保我的应用将来不会出问题?Can I rely on its structure remaining stable so my application won't break in the future?
- 我是否可以为了自己的目的处理这些数据,例如依据 GDPR?Am I allowed to process the data for my purpose, for example under the GDPR?
- 在处理数据或重新分享结果时,我是否需要采取特殊的预防措施,例如保护个人数据?Do I have to apply special precautions, for example for personal data, when processing the data or resharing the results?
- 我可以与谁分享这些预测结果?With whom may I share the resulting predictions?
上述问题可以通过多种方式进行分类,但它们表明,信任问题不仅关乎 Alex 是否能够信任数据来源(涉及质量、可靠性和法律问题),还关乎结果的接收方是否值得信赖,能够妥善处理数据。The questions above can be categorized in various ways, but they show that the matter of trust is not only about whether Alex can trust the source of the data (in terms of quality, reliability, legal issues) but also whether the recipients of the results are trustworthy to take care of the data.
数据契约不仅能帮助我们回答这些问题,还能确保数据持续得到可信赖的处理。Data contracts are a way to answer these questions not just once, but to ensure the trustworthy processing of data continuously.
一个简单的数据契约示例A Simple Example Data Contract
最简单来说,数据契约是对数据提供方所提供数据形态的描述,例如数据模式。下面是 Alex 找到的数据集描述可能包含的一段内容。所有示例都将采用开放数据契约标准(ODCS)进行说明,因为它是事实上的行业标准,由 Linux 基金会旗下的 Bitol 项目负责治理(在 Thoughtworks 技术雷达中被评为“采用”)。In its simplest form, a data contract is a description of the shape of the data that a data provider is offering, e.g., a schema. Here is an excerpt of what the description of the dataset that Alex found could look like. We will illustrate all the examples using the Open Data Contract Standard (ODCS) as it is the de facto industry standard governed by the Bitol project at the Linux Foundation (rated Adopt in the Thoughtworks Technology Radar).
apiVersion: "v3.2.0"
kind: "DataContract"
id: "customers"
name: "Customers"
version: "1.0.0"
status: "active"
schema:
- name: "customers"
physicalType: "TABLE"
description: "All customers holding a life insurance policy since 2020-01-01"
properties:
- name: "customer_id"
logicalType: "string"
primaryKey: true
- name: "customer_name"
businessName: "Customer Name"
logicalType: "string"
physicalType: "VARCHAR(100)"
examples:
- "Alex Doe"
classification: "restricted"
看到这份简单的数据契约后——它很可能会以页面的形式呈现在公司的数据市场中,而不是原始的 YAML 格式——Alex 对这些数据是否足以用于实现预测已经有了更清晰的认识。不过,Alex 还想知道这些数据上次更新时间,以及所声明的字段是否始终包含正确的数据。在 ODCS 中,可以通过质量规则来描述数据质量,也可以通过服务级别来规定数据在运行期间的行为。以下是如何扩展数据契约以解决这些问题:Seeing this simple data contract, most likely rendered as a page in the company's data marketplace rather than as raw YAML, Alex already has a much better idea whether the data will be sufficient for implementing the prediction. But Alex is wondering when the data was last updated and if the declared fields will consistently contain correct data. In ODCS, there are specific elements to describe the quality of the data through quality rules as well as service levels that specify runtime behavior over time. Here is how the data contract can be extended to address these issues:
schema:
- name: "customers"
properties:
- name: "customer_name"
quality:
- type: "sql"
description: "Expect less than 1% empty name fields"
query: |
SELECT AVG(
CASE
WHEN customer_name IS NULL
OR TRIM(customer_name) = ''
THEN 1
ELSE 0
END
)
FROM customers
mustBeLessThan: 0.01
slaProperties:
- property: "freshness"
value: 24
unit: "hours"
element: "customers.last_updated_at"
description: "Within 24 hours of the last update"
看到这些保障后,Alex 对基于此数据集构建的应用能够持续稳定运行、不会在数据集下次更新时崩溃,有了更大的信心:活跃状态和 1.0.0 版本表明这是一个稳定且持续维护的数据集;质量和 SLA 描述则有助于可靠地处理数据。而真正的信任,来自这些保障经过自动验证。Seeing these guarantees, Alex has much more confidence that building an application based on this dataset will be sustainable and not fall apart at the next update of the dataset: the active status and the 1.0.0 version indicate that this is a stable and maintained dataset; the quality and SLA descriptions allow for processing the data reliably. And actual trust comes when these guarantees are verified automatically.
这对 AI 智能体意味着什么?What Does This Mean for AI Agents?
现在想象一下,Alex 不是人类,而是一个 AI 智能体。对数据心存疑虑的人类会犹豫,或者询问数据的所有者。智能体却不会这样做:正如 Pramod Sadalage 和 Prem Chandrasekaran 在《让你的数据为代理式 AI 做好准备》中所说,智能体会把每个值都当作事实。缺乏信任会拖慢人类,却会让智能体自信地得出错误结果;而人类也因此不再相信智能体能够独立处理数据。数据契约通过为智能体提供明确的元数据,避免它们不得不靠猜测来填补信息,从而打破这一恶性循环。Now imagine that Alex is not a human but an AI agent. A human who distrusts data hesitates, or asks the people who own it. An agent does neither: as Pramod Sadalage and Prem Chandrasekaran put it in Making Your Data Ready for Agentic AI, agents treat every value as truth. Where a lack of trust slows humans down, it makes agents produce confidently wrong results, and humans in turn stop trusting agents to work with data on their own. Data contracts break that loop by giving agents the explicit metadata they would otherwise have to guess.
代理在执行每项任务时,都会遇到 Alex 曾经遇到的同样问题,却无人可问。数据契约以代理能够据此采取行动的形式解答这些问题:发布到代理可以搜索的市场后,数据首先变得可发现;其架构和语义告诉代理如何正确查询和联接数据;质量规则和服务级别让代理知道结果有多可信;使用条款则说明它可以做什么。这正是为什么,从与数据对话到生成完整的数据管道,代理式应用场景正成为采用数据契约的主要理由之一。An agent has the same questions Alex had, on every task, and nobody to ask. A data contract answers them in a form the agent can act on: published to a marketplace that agents can search, it makes the data discoverable in the first place; its schema and semantics tell the agent how to query and join the data correctly; its quality rules and service levels tell it how far to trust the result; and its terms of use tell it what it is allowed to do. That is why agentic use cases, from chatting with your data to generating whole data pipelines, are becoming one of the main reasons to adopt data contracts.
数据契约包含什么内容What's in a Data Contract
合同不就是双边协议吗?Isn't a contract a bilateral agreement?
从法律角度来说,合同是两个或多个当事方之间达成的协议。在当前的数据实践中,数据合同由提供方单方面发布,说明其向任何使用方作出的承诺和使用条款。但这并不意味着它在实际效果上是单方面的。软件工程师熟悉 Bertrand Meyer 的契约式设计(Design by Contract):例程声明自身的前置条件和保证,而这会约束双方,无须协商。许多数据合同也会先与其主要使用方协商,尤其是在采用契约优先的工作方式时;即使是已发布的合同,也能保护双方:使用方获得明确的承诺,而提供方也同样明确地说明自己不作出哪些承诺。本文始终在上述由提供方发布的意义上使用这一术语,后文则会介绍针对与某个特定使用方之间双边关系的访问协议。In legal terms, a contract is an agreement between two or more parties. In current data practice, a data contract is published one-sidedly by the provider, describing its promises and terms of use towards any consumer. That does not make it one-sided in effect. Software engineers know this form from Bertrand Meyer's Design by Contract: a routine declares what it requires and what it guarantees, and that binds both sides without a negotiation. Many data contracts are also negotiated with their main consumers first, especially when working contract-first, and even a published contract protects both sides: consumers get explicit promises, and the provider states just as explicitly what it does not promise. Throughout this article, we use the term in this provider-published sense, and later introduce the access agreement for the bilateral relation with one specific consumer.
在查看各个部分之前,先了解数据契约的基本特征会有所帮助。数据契约是:Before we look at the individual sections, it helps to understand what characterizes a data contract in the first place. A data contract is:
- 机器可读。数据契约是一种结构化文档,通常采用 YAML 格式,而不是埋在维基中的散文。工具、流水线和 AI 代理可以直接解析并据此采取行动,无需人类先将其转换成机器可读的形式。Machine-readable. A data contract is a structured document, typically YAML, not prose buried in a wiki. Tools, pipelines, and AI agents can parse it and act on it directly, without a human having to translate it first.
- 可验证。它的承诺足够具体,可以根据实际数据进行核查。诸如“空姓名少于 1%”这样的质量规则并非一种期望,而是一项工具可以评估并判定为通过或未通过的断言。Verifiable. Its promises are concrete enough to be checked against the actual data. A quality rule such as “less than 1% empty names” is not an aspiration but an assertion that tooling can evaluate and either pass or fail.
- 具备版本管理。数据契约带有版本号,并按照明确的方案演进,让使用方能够分辨无害变更与破坏性变更,也让提供方能够平稳地逐步引入新版本并淘汰旧版本。Versioned. A data contract carries a version and evolves under a clear scheme, so consumers can tell a harmless change from a breaking one, and providers can phase new versions in and old ones out gracefully.
- 由提供方驱动。它由生成数据且最了解数据的一方单方面发布。他们对自己作出的承诺负责,这使接口责任转移到掌握相关知识、且能够兑现或违背承诺的一方。Provider-driven. It is published one-sidedly by the party that produces the data and knows it best. They own the promises they make, which shifts responsibility for the interface to where the knowledge sits and where the promises can be kept or broken.
- 面向消费者。尽管它由提供方编写,但其目标读者是消费者:它记录了消费者判断数据是否适合其用途并长期信赖该数据所需的架构、语义、质量保证和使用条款。Consumer-oriented. Even though the provider writes it, it is written for the consumer: it captures the schema, semantics, quality guarantees, and terms of use a consumer needs to decide whether the data fits their purpose and to rely on it over time.
- 元数据的事实来源。它是对数据集的权威描述。目录、市场、文档和智能体都以它为依据,而不是各自维护彼此不一致的副本。The source of truth for metadata. It is the authoritative description of the dataset. Catalogs, marketplaces, documentation, and agents all draw from it, rather than each maintaining their own divergent copy.
此类数据契约通常使用开放数据契约标准进行定义。Such a data contract is typically defined using the Open Data Contract Standard.
开放数据契约标准Open Data Contract Standard
开放数据合同标准的起源The Origin of the Open Data Contract Standard
开放数据合约标准(Open Data Contract Standard)的故事始于 PayPal。他们开发了一种 YAML 格式,用于在内部描述数据合约,随后在 Jean-Georges Perrin 的推动下,于 2023 年以 Data Contract Template 的名称将其开源。仅仅几个月后,它便演变为开放数据合约标准 2.2,成为 Linux 基金会 Bitol 项目的创始标准。该标准中仍包含许多 PayPal 专属字段。2024 年发布 3.0 版时,这些 PayPal 专属内容被移除或进行了通用化处理,为更广泛的采用做好了准备。与此同时,另一种格式也备受关注:由 Jochen Christ 和 Simon Harrer 发布的数据合约规范(Data Contract Specification)。它尤其受到关注,是因为它与一款名为 Data Contract CLI 的开源工具同步开发,而这款工具也让它广为流行。2025 年发布的 ODCS 3.1 拉近了两项标准之间的距离,并为 Data Contract CLI 增加了对 ODCS 3.1 的原生支持。此后,数据合约规范被弃用,ODCS 成为描述数据合约的事实标准。2026 年,ODCS 3.2 新增了 AI 上下文,用于告知 AI 代理及其他工具数据的预期用途。The story of the Open Data Contract Standard began at PayPal. They developed a YAML format to describe their data contract internally, and then open sourced it under the name Data Contract Template in 2023, thanks to Jean-Georges Perrin. Only a few months later, it evolved into the Open Data Contract Standard 2.2 as the founding standard of the Bitol project at the Linux Foundation. It still contained a lot of fields specific to PayPal. With the release of version 3.0 in 2024, these PayPal specifics were removed or generalized, preparing it for wider adoption. At the same time, another format had gotten a lot of attention, the Data Contract Specification, published by Jochen Christ and Simon Harrer, especially as it was developed in sync with an open source tool named Data Contract CLI that made it popular. With the release of ODCS 3.1 in 2025, bringing both standards close together, and adding native support for ODCS 3.1 in the Data Contract CLI, the Data Contract Specification was retired, making ODCS the de facto standard for describing data contracts. In 2026, ODCS 3.2 added the AI context, which tells AI agents and other tools how the data is meant to be used.
开放数据契约标准(ODCS)定义了一种 YAML 格式,用于以标准化的方式描述数据契约。你已经在本文引言中看过该 YAML 格式的一个简短示例。开放数据契约标准是 Bitol 项目的一部分;Bitol 是 Linux 基金会的一个毕业项目,因此它也属于一系列元数据标准。开放数据契约标准的规范可在 GitHub 上公开获取,目前已获得超过 1000 颗星。该标准还附带一个 JSON Schema,用于帮助验证 YAML 文件是否符合标准。The Open Data Contract Standard (ODCS) defines a YAML format for specifying data contracts in a standardized way. You've already seen a short example of that YAML in the introduction of this article. The Open Data Contract Standard is part of the Bitol project, a graduate project of the Linux Foundation, and thereby part of a family of metadata standards. The specification of the Open Data Contract Standard is publicly available on GitHub, where it has over 1000 stars. The standard comes with a JSON schema to help validate YAML files in terms of standard compliance.
图 1:开放数据契约标准 v3.2 的各个部分Figure 1: The sections of the Open Data Contract Standard v3.2
开放数据契约标准包含许多不同类别的元数据,接下来我们将根据撰写本文时的最新版本 ODCS 3.2,通过每个部分的示例代码片段逐一介绍。您也可以在 datacontract.com 上查看同一内容的交互式分步讲解。The Open Data Contract Standard comprises many different categories of metadata, which we will cover shortly using example code snippets for each part based on ODCS 3.2, the latest version at the time of writing. An interactive, step-by-step walkthrough of the same sections is available on datacontract.com.
apiVersion: "v3.2.0" kind: "DataContract" id: "customers" name: "Customers" version: "1.0.0" status: "active"
每份数据契约都始于其基本信息:标准版本、唯一标识符、名称、数据契约版本号和状态。这些元数据用于标识契约,并支持版本管理和生命周期管理。Every data contract starts with its fundamentals: the version of the standard, unique identifier, name, data contract version number, and status. This metadata identifies the contract and enables versioning as well as lifecycle.
架构与数据质量Schema and Data Quality
schema:
- name: "customers"
physicalType: "TABLE"
description: "All customers holding a life insurance policy since 2020-01-01"
properties:
- name: "customer_id"
logicalType: "string"
primaryKey: true
- name: "customer_name"
businessName: "Customer Name"
logicalType: "string"
physicalType: "VARCHAR(100)"
required: true
examples:
- "Alex Doe"
classification: "restricted"
tags:
- "pii:true"
- name: "annual_premium"
logicalType: "integer"
physicalType: "INTEGER"
description: "Annual premium in cents"
required: true
logicalTypeOptions:
minimum: 0
- name: "customer_status"
logicalType: "string"
physicalType: "TEXT"
examples:
- "active"
- name: "last_updated_at"
logicalType: "date"
physicalType: "TIMESTAMP"
description: "Timestamp of the last update to the customer record"
模式定义了数据的结构和语义。在我们的示例中,它是一张包含多个列的表,但相同的结构也可以描述 Kafka 主题中的消息、对象存储中的文件,或 API 的负载。每一列都包含技术细节、业务语义和治理属性。例如,年度保费以美分为单位存储为整数,这遵循了公司处理货币值的惯例。你还可以在数据契约中定义列与表之间的关系,例如外键。The schema defines the structure and semantics of your data. In our example that is a table with its columns, but the same structure describes the messages of a Kafka topic, files in an object store, or the payload of an API. Each column includes technical details, business semantics, and governance attributes. For example, that the annual premium is stored in cents as an integer, following the company's convention on how to handle monetary values. You can also define relationships like foreign keys between columns and tables within the data contract.
schema:
- name: "customers"
quality:
- type: "sql"
description: "Expect more than 100K rows"
query: "select count(*) from customers"
mustBeGreaterThan: 100000
properties:
- name: "customer_name"
quality:
- type: "sql"
description: "Expect less than 1% empty name fields"
query: |
SELECT AVG(
CASE
WHEN customer_name IS NULL
OR TRIM(customer_name) = ''
THEN 1
ELSE 0
END
)
FROM customers
mustBeLessThan: 0.01
- name: "customer_status"
quality:
- type: "library"
description: "Only valid customer statuses"
metric: "invalidValues"
arguments:
validValues:
- "active"
- "lapsed"
- "cancelled"
mustBe: 0
数据质量规则可确保数据符合预期。你可以定义有效值约束、行数阈值、自定义 SQL 验证逻辑等检查项,甚至可以直接用文本形式描述质量规则。阈值可以是绝对值,例如最小行数;也可以是相对值,例如空姓名的比例不超过 1%。借助合适的工具,这些检查可以自动验证。Data quality rules ensure that data meets expectations. You can define checks like valid value constraints, row count thresholds, custom SQL validation logic, or even simply a quality rule in textual form. Thresholds can be absolute, like a minimum row count, or relative, like at most 1% empty names. Those checks can be automatically verified with the right tooling.
所有权和支持渠道Ownership and Support Channels
team:
name: "customer-data"
members:
- username: "carola@example.com"
name: "Carola Doe"
role: "Owner"
support:
- channel: "#customer-data-support"
tool: "slack"
url: "https://example.slack.com/archives/C123456789"
所有权是数据契约的核心。团队会明确由谁负责数据契约及其维护工作,包括相关成员及其角色。添加支持渠道,说明数据使用者如何联系负责人。这种可联系、可追责的责任机制对于建立数据信任至关重要。Ownership is central to data contracts. The team defines who owns and maintains the data contract, including its members with their roles. Add support channels to specify how data consumers can reach out to the owners. That reachable responsibility is critical in building trust in data.
使用条款和服务级别协议 (SLA)Terms of Use and SLAs
description:
purpose: "Provides customer master data for analytics and reporting"
usage: "Used by analytics team for customer insights and cross-sell prediction"
limitations: "Contains only customers with an active policy"
authoritativeDefinitions:
- url: "https://example.com/policies/gdpr-compliance"
type: "businessDefinition"
description: "GDPR compliance policy for handling customer data"
使用条款帮助数据使用者了解可以和不可以如何使用数据,从而确立清晰的治理边界。该标准允许你定义数据的用途、使用指南和限制,还可以链接到外部政策,例如隐私政策或许可协议。The terms of use help data consumers understand what they can and cannot do with the data, establishing clear governance boundaries. The standard lets you define the purpose, usage guidelines, and limitations for your data, as well as point to external policies such as privacy policies or license agreements.
slaProperties:
- property: "retention"
value: 5
unit: "year"
description: "Data will be deleted after 5 years"
- property: "freshness"
value: 24
unit: "hours"
element: "customers.last_updated_at"
description: "Within 24 hours of the last update"
服务级别协议定义了数据新鲜度、数据保留期限或延迟等保证。每项保证都以可测量的方式表述:每次测试契约时,都会根据 last_updated_at 检查上述新鲜度承诺;如果违反承诺,系统会向负责团队发出警报。Service Level Agreements define guarantees such as freshness of the data, data retention, or latency. Each one is stated so that it can be measured: the freshness promise above is checked against last_updated_at every time the contract is tested, and a breach alerts the owning team.
数据的位置Location of the Data
servers:
- server: "production"
type: "snowflake"
environment: "prod"
account: "insurance-corp"
database: "prod_lifeinsurance"
schema: "dp_customers_v1"
服务器指定数据实际存储的位置。它们包含访问数据所需的连接详细信息,但不包括任何凭据。该标准支持指定几乎所有可直接存储数据的系统:数据平台和数据库,例如 Snowflake、Databricks、BigQuery、Oracle 和 Postgres;事件流,例如 Kafka、Kinesis 或 Pub/Sub;S3 上的文件;甚至 SFTP 服务器上的 CSV 文件,以及许多其他系统。如果某个系统不受支持,该标准还提供了自定义服务器类型作为备用选项。Servers specify where the data actually lives. They include the connection details to access the data, excluding any credentials. The standard supports specifying basically any system that can hold data directly: data platforms and databases such as Snowflake, Databricks, BigQuery, Oracle, and Postgres, event streams such as Kafka, Kinesis, or Pub/Sub, files on S3, or even CSV files on an SFTP server, and many others. It also provides the fallback to a custom server type if a system is not supported.
对于事件流,服务器条目指定集群和消息格式,而架构描述主题:For an event stream, the server entry names the cluster and the message format, and the schema describes the topic:
servers:
- server: "production"
type: "kafka"
environment: "prod"
host: "kafka.example.com:9092"
format: "avro"
schema:
- name: "customer_events"
physicalType: "topic"
角色与安全性Roles & Security
roles:
- role: "customers_reader"
access: "read"
description: "Read access to all customer data"
角色描述消费者如何获得数据访问权限。每个角色都会指定数据平台上的一个 IAM 角色(例如 Snowflake 角色),以及该角色授予的访问权限类型。提供方通常会定义多个角色,例如一个包含个人数据,另一个不包含个人数据。合同不会列出谁持有某个角色;访问请求获批时,会针对每个消费者单独决定这一点,正如我们将在数据市场一节中看到的那样。Roles describe how consumers get access to the data. Each role names an IAM role on the data platform, such as a Snowflake role, and the kind of access it grants. Providers often define several roles, for example one that includes personal data and one that doesn't. The contract doesn't list who holds a role; that is decided per consumer when an access request is approved, as we'll see in the section on data marketplaces.
AI 上下文AI Context
context:
instructions: >
Use this data for analytics on life insurance customers.
Annual premiums are stored in cents; divide by 100 before
reporting amounts.
constraints:
- constraint: >
Do not use this data to make decisions about individual
customers, such as pricing a policy or assessing a claim.
verifiedStatements:
- question: "How many active customers do we have?"
answer: |
SELECT COUNT(*)
FROM customers
WHERE customer_status = 'active'
AI 上下文是专门为 AI 智能体编写的指导内容。这些指令相当于数据集的系统提示,例如告知智能体保费以美分为单位存储。约束条件说明智能体不得对数据做什么。经验证的陈述则将常见的业务问题与提供方已核验过的查询配对起来,这样智能体就能复用正确答案,而不必猜测。The AI context is guidance written specifically for AI agents. The instructions act like a system prompt for the dataset, for example telling an agent that premiums are stored in cents. The constraints state what an agent must not do with the data. And the verified statements pair common business questions with a query the provider has checked, so an agent can reuse a correct answer instead of guessing one.
数据使用定价Pricing the Use of Data
价格可以表示一项内部收费,以体现数据的价值。实际使用中,这一项通常留空,或者按平台上访问数据的实际成本转嫁费用,例如:每扫描 1 TB 收费 10 美元。The price can express an internal charge that reflects the value of the data. In practice, it is usually left empty or passes on what accessing the data actually costs on the platform, as in this example: 10 USD per terabyte scanned.
price: priceAmount: 10 priceCurrency: "USD" priceUnit: "per TB scanned"
内置可扩展性Built-in Extensibility
由于每家公司都不相同,该标准内置了两种扩展机制。每个层级都可以使用自定义属性,承载标准本身无法识别的元数据,例如提供数据的法律实体,或用于驱动基础设施配置的平台清单引用。供应商也会使用同一种机制来添加功能。权威定义可以将契约或其中的任意元素关联到其他地方定义的内容,包括其他开放标准:如下例所示,关联到一个提供相同数据的 REST API 的 OpenAPI 规范。我们的建议依然是:优先使用标准的官方属性,并尽量减少自定义属性。As every company is different, the standard has two built-in mechanisms to extend it. Custom properties, available on every level, carry metadata the standard does not know, such as the legal entity that provides the data, or a reference to a platform manifest that drives infrastructure provisioning. Vendors use the same mechanism to add functionality on top. Authoritative definitions link the contract, or any element in it, to something defined elsewhere, including other open standards: in the example below, the OpenAPI specification of a REST API that serves the same data. Our advice remains: prefer the official standard properties, and keep custom ones to a minimum.
customProperties:
- property: "legalEntity"
value: "Insurance Corp AG"
description: "Legal entity that owns and provides this data"
authoritativeDefinitions:
- url: "https://example.com/apis/customers/openapi.yaml"
type: "openapi"
description: "OpenAPI specification of the REST API serving this data"
语境中的数据契约Data Contracts in Context
数据契约很少孤立存在,它们的价值会随着所连接的对象增多而提升。在实践中,三种连接尤为重要:将列关联到领域模型,而不是重复描述其含义;在数据产品的端口上设置契约;并让契约充当产品页面,供使用者据此申请访问权限。Data contracts rarely stand alone, and their value grows with what they connect to. Three connections matter most in practice: link columns to your domain model instead of restating their meaning, put contracts on the ports of data products, and let the contract be the product page that consumers request access from.
将数据契约关联到本体Linking Data Contracts to Ontologies
尤其是在智能体处理数据并整合来自不同来源的数据时,仅记录各个数据集的语义是不够的。正如《让数据为智能体 AI 做好准备》中所指出的,必须在一个统一的语义层中定义跨数据源的语义。将语义(尤其是本体)与数据契约相结合,可以解决两个具体问题:Especially when agents work with data and combine data from different sources, documenting the semantics of individual datasets is not enough. As pointed out in Making Your Data Ready for Agentic AI, semantics need to be defined across data sources in an overarching semantic layer. Combining semantics, ontologies in particular, with data contracts solves two concrete problems:
- 元数据去重:它们减少了数据生产者的重复工作。像“客户 ID”这样的概念可以只定义一次,并在定义中包含示例、机密性和隐私分类以及描述;数据契约只需链接到该定义,即可继承集中定义的特征,而不必再次陈述这些内容。Metadata de-duplication: They reduce duplication for the data producer. A concept such as Customer ID can be defined once, including its examples, confidentiality and privacy classification, and description, and the data contracts simply link to that definition, inheriting the centrally defined characteristics rather than restating them.
- 语义一致性与互操作性:它们使数据消费者能够互操作来自两个或更多数据契约的数据。通过将列关联到共同的概念定义,消费者可以判断两个名称相似的列是否实际含义相同,也可以判断两个名称不同的列是否含义相同。这是概念层面的一致性,而不仅仅是匹配主键和外键的问题,尽管这样的共同概念正是可靠连接键的基础。Semantic consistency and interoperability: They make data from two or more data contracts interoperable for the data consumer. By linking columns to a shared conceptual definition, a consumer can tell whether two similarly named columns actually mean the same thing, and whether two differently named ones do. This is consistency at the conceptual level, not merely a matter of matching primary and foreign keys, even though such a shared concept is exactly what makes a reliable join key.
图 2:两个数据契约将各自的属性关联到本体中的同一概念,因此使用者知道如何将它们联接起来。Figure 2: Two data contracts link their properties to the same concept in an ontology, so a consumer knows how to join them
schema:
- name: "customer_360"
properties:
- name: "cid"
authoritativeDefinitions:
- type: "semantics"
url: "https://example.com/ns/Customer.id"
核心概念是通过 authoritativeDefinitions 元素,将数据契约指向本体中的一个元素。这样,数据契约就映射到了本体中。只需使用该本体中的 IRI 或 URL 标识该元素。本体本身可以使用 RDF、OWL 等标准来描述,也可以使用 Apache Ossie 项目中颇具前景的本体标准;该项目目前正在 Apache 软件基金会孵化。The core concept is to point from the data contract to an element in an ontology via an authoritativeDefinitions element. That way, the data contract maps into the ontology. The element simply needs to be identified by an IRI or URL within that ontology. The ontology itself can be described using standards like RDF, OWL, or using the promising ontology standard within the Apache Ossie project, currently incubating at the Apache Software Foundation.
数据产品构建于数据契约之上Data Products Build Upon Data Contracts
数据契约与数据网格原则Data Contracts and the Data Mesh Principles
了解数据网格的读者会在数据契约中发现它的四项原则:Readers coming from data mesh will find its four principles in a data contract:
- 领域所有权。团队和支持部分会说明谁拥有这些数据以及如何联系他们:负责生成数据、最了解这些数据的领域团队。Domain ownership. The team and support sections name who owns the data and how to reach them: the domain team that produces the data and knows it best.
- 将数据作为产品。合同就是数据市场中的产品详情页,面向需要判断数据是否符合自身用途的消费者编写。Data as a product. The contract is the product details page in the data marketplace, written for the consumer who decides whether the data fits their purpose.
- 自助式数据平台。平台为每个团队提供的流水线都内置了代码检查、破坏性变更检测和数据测试,因此团队无需自行构建这些功能。Self-serve data platform. Linting, breaking change detection, and data tests come with the pipeline that the platform gives every team, so no team has to build them itself.
- 联邦式计算治理。分类和使用条款等全局策略被写入合约,并由工具强制执行,而非通过人工审核。Federated computational governance. Global policies such as classification and terms of use are written into the contract and enforced by tooling rather than by manual review.
数据契约与数据产品尤其相辅相成。数据产品将产品思维引入数据领域,也是数据网格等现代去中心化数据架构的核心组成部分。数据契约是一种接口描述语言,能够明确并验证数据产品的各个端口。Data contracts go particularly well together with data products, which bring product thinking to data, and are a central part of modern, decentralized data architectures such as data mesh. Data contracts are the interface description language that makes the ports of a data product explicit and verifiable.
图 3:一个具有一个输入端口和三个输出端口的数据产品,每个端口都由数据契约描述;其中两个输出端口提供同一数据契约的不同版本Figure 3: A data product with one input port and three output ports, each described by a data contract; two output ports offer different versions of the same contract
自 2025 年起,Bitol 标准系列还新增了一项用于描述数据产品元数据的标准——开放数据产品标准(ODPS),该标准以开放数据契约标准为基础。Since 2025, the family of Bitol standards also has a standard for describing the metadata for data products, the Open Data Product Standard (ODPS), building upon the Open Data Contract Standard.
描述 Customers 数据产品的 customers.odps.yamlcustomers.odps.yaml, describing the Customers data product
apiVersion: "v1.1.0"
kind: "DataProduct"
id: "customers"
name: "Customers"
status: "active"
description:
purpose: >
Master data for all customers holding a life insurance
policy. All customers since 2020-01-01.
usage: "Used by analytics teams for customer insights and cross-sell prediction"
limitations: "Contains only customers with an active policy"
inputPorts:
- name: "customer_events"
version: "1.0.0"
contractId: "kafka_customer_events"
outputPorts:
- name: "customers_pii_snowflake_v1"
description: "All customer records, with PII."
version: "1.0.0"
contractId: "customers_pii_snowflake"
- name: "customers_pii_snowflake_v2"
description: "All customer records, with PII."
version: "2.0.0"
contractId: "customers_pii_snowflake"
- name: "customers_npii_snowflake_v1"
description: "All customer records, without PII data."
version: "1.0.0"
contractId: "customers_npii_snowflake"
在上面的 ODPS 示例中,数据产品的端口指的是使用 ODCS 定义的数据契约。ODPS 和 ODCS 文件共同构成数据产品元数据。数据产品是一个整体:生成数据的代码和管道、数据本身,以及描述数据的元数据。这就是将数据产品视为架构量子的概念:一个自包含单元,具有由 ODCS 规定的输入端口和输出端口作为接口。In the ODPS example above, the ports of a data product refer to data contracts defined using ODCS. Together, the ODPS and ODCS files form the data product metadata. The data product is the whole thing: the code and the pipeline that produces the data, the data itself, and the metadata that describes it. This is the concept of a data product as an architectural quantum, a self-contained unit with input and output ports as ODCS-specified interfaces.
由于这两种标准彼此兼容,我们可以将所有权相关信息(例如团队和支持渠道),以及适用于所有数据契约的信息,移至数据产品描述中,从而减少重复。As the two standards are compatible with each other, we can move the information regarding ownership, such as teams and support channels, as well as information that applies to all data contracts, into the data product description, reducing duplication.
数据产品和 ODPS 固然有用,但输出端口的数据契约仍是核心要素。它们承载着提供方作出的承诺,许多相关方都会基于这些契约开展工作。As useful as data products and ODPS are, the data contracts at the output ports remain the central element. They hold the promises the provider makes, and many parties work with them.
图 4:数据契约至少对四方至关重要:提供方、使用方、数据治理团队和数据产品平台Figure 4: The data contract is central to at least four parties: provider, consumer, data governance, and data product platform
提供方发布数据契约,使用方依赖该契约。数据产品平台读取它,以确定需要注册、配置和监控什么。数据治理团队读取它,以检查所有权、分类和使用条款相关政策是否得到遵守。因此,归根结底,数据契约也是数据市场中的产品详情页。The provider publishes the data contract, and consumers rely on it. The data product platform reads it to know what to register, provision, and monitor. Data governance reads it to check that policies on ownership, classification, and terms of use are followed. And that is why, in the end, the data contract is also the product details page in a data marketplace.
数据契约是数据市场中的“产品详情页”Data Contracts are the “Product Details Page” in a Data Marketplace
大多数企业都拥有某种形式的数据市场,让数据可以像商品一样供人选购。在数据市场中,数据契约包含所有必要信息,帮助数据消费者判断所提供的数据是否符合其预期用途的需求。确认无误后,消费者便会请求访问契约所描述的数据,并注明处理目的;该目的应符合数据契约的使用条款。这一请求相当于客户在商品详情页上点击“购买”。Most enterprises have some sort of data marketplace, where data becomes shoppable. There, data contracts contain all the information for data consumers to make an informed decision about whether the provided data is what they need for their intended purpose. When convinced, a consumer requests access to the data described by the contract, including a processing purpose that should be in line with the terms of use of the data contract. This request is the counterpart of a customer clicking “buy” on a product details page.
该请求会创建一份访问协议,主要由三部分组成:所请求数据的数据契约、声明的处理目的以及请求方消费者。只有在提供方批准该请求后,访问协议才会生效。此时,数据产品平台才会授予实际的数据访问权限。The request creates an access agreement consisting mainly of three parts: the requested data's data contract, the stated processing purpose, and the requesting consumer. The access agreement only becomes effective when the provider approves the request. Only then does the data product platform grant the actual data access.
图 5:提供方与 AI 代理之间的访问协议:代理请求访问,提供方批准后,代理即可在短时间内访问数据Figure 5: An access agreement between the provider and an AI agent: the agent requests access, the provider approves, and the agent gets short-lived access to the data
不要把两者混为一谈。数据契约由提供方单方面发布,不针对任何特定消费者,也不涉及时间概念。访问协议则是双边的,与日常生活中的合同更为接近:消费者将其作为请求创建,只有提供方批准后才具有约束力,就像合同只有在双方签字后才生效。访问协议始终包含生效日期,也可以选择设置到期日期;对于 AI 智能体,获准访问的期限可能短至几分钟。目前还没有访问协议的标准,但 Bitol 项目正在制定一项标准:一份关于开放访问协议标准(OAAS)的 RFC 提议记录谁可以访问哪个输出端口、访问目的是什么,以及访问期限有多长。Don't confuse the two. A data contract is published one-sidedly by the provider, refers to no specific consumer, and has no notion of time. An access agreement is bilateral, much closer to a contract in everyday life: the consumer creates it as a request, and it only becomes binding once the provider approves it, just as a contract binds only when both parties have signed. It always has a start date and, optionally, an expiration date; for AI agents, the granted access period can be as short as a few minutes. There is no standard for access agreements yet, but the Bitol project is working on one: an RFC for an Open Access Agreement Standard (OAAS) proposes recording who may access which output port, for what purpose, and for how long.
产品页面不仅展示制造商的描述,还会显示评价。对于数据来说,与之对应的是合约的履约记录:将测试结果发布到市场后,合约就能在每项承诺旁展示其兑现情况,例如过去 30 天中有 29 天满足了数据新鲜度要求,或者团队通常需要多长时间才能修复未兑现的承诺。正如《为你的数据产品打造一个“Amazon.com”》一文所述,这类信任信号能让消费者了解的信息远不止承诺本身。A product page also shows reviews, not just the manufacturer's description. The equivalent for data is the contract's track record: with test results published to the marketplace, it can show next to each promise how well it was kept, for example that freshness was met on 29 of the last 30 days, or how long the team typically takes to fix a broken promise. Such trust signals, as described in Building an “Amazon.com” for Your Data Products, tell a consumer more than the promise alone.
使用数据契约工作Working with Data Contracts
编写数据契约很容易,真正考验团队成败的是如何与它共存。要做好这一点,就要像对待 API 一样严谨地对待数据契约:有意地创建它,将它与代码放在一起,在不破坏使用方的前提下不断演进,并对其进行自动检查。Writing a data contract is the easy part; living with it is where teams succeed or fail. Doing it well means treating a data contract with the same rigor as an API: creating it deliberately, keeping it next to the code, evolving it without breaking consumers, and checking it automatically.
数据优先 vs. 契约优先Data-first vs. Contract-first
如果数据已经与其他团队共享,例如以数据仓库中的表的形式共享,我们就可以将其纳入契约管理,明确数据提供方作出的承诺,理想情况下将其作为数据产品的输出端口。为此,我们需要在数据契约中体现数据集现有的结构,然后逐步补充所有隐含的承诺。可以借助开源工具 Data Contract CLI 启动这一过程:它能够转换描述数据结构的现有元数据,例如 SQL DDL、JSON Schema 或 Avro Schema,并生成数据契约的初稿,之后再对其进行完善。If data is already shared with other teams, for example as tables in a data warehouse, we can put it under contract to make the promises of the data provider explicit, ideally as the output port of a data product. For that, we need to represent the existing structure of the dataset in the data contract, and then add all the implicit promises iteratively. This can be kickstarted by using the open source tool Data Contract CLI that can convert existing metadata describing the structure of the data such as SQL DDL, JSON Schema, or Avro Schema, and generate a first draft of a data contract, which is enriched afterwards.
不过,生成只是起点。初稿经过完善并发布后,方向就反转了:数据契约趋于稳定,成为事实依据,而数据必须遵循它。如果底层表中的某一列后来被重命名,数据契约不会重新生成。相反,契约测试会失败,而这次重命名必须按其本质来处理:一次破坏性变更。Generation is only the starting point, though. Once the first draft has been enriched and published, the direction flips: the data contract is stable and becomes the source of truth, and the data has to follow it. If a column in the underlying table is renamed later, the contract is not regenerated. The contract test fails instead, and the rename has to be handled as what it is: a breaking change.
另一种方法是,先围绕实际需要构建什么展开讨论,并在编写任何代码之前明确数据契约。根据我们的经验,采用研讨会的形式并由一名主持人引导,效果很好;数据的潜在提供方和使用方可以共同起草数据契约的初稿。Another approach is to first start with a conversation on what should actually be built, leading to defining the data contract before any code is written. In our experience, a workshop format with a facilitator works very well, where the potential provider of the data and data consumers work together on a first draft of the data contract.
你可以用任何适合小组的媒介来记录这份草稿:You can capture this draft in whatever medium suits the group:
- 白板,或你喜欢的 YAML 编辑器A whiteboard, or a YAML editor of your choice
- 数据产品画布,其中数据契约是核心组成部分The Data Product Canvas, in which the data contract is a central part
- 符合 ODCS 规范的 Excel 模板——业务用户每天都在使用的工具An ODCS-compliant Excel template, the tool that business users work with every day
- 开源数据契约编辑器The open source Data Contract Editor
最终,必须形成一份符合标准的数据契约,并通过迭代不断完善,直至各方满意;随后以此为依据启动管道的实现,从而按照约定的数据契约实际提供数据。In the end, a standard-compliant data contract must emerge, which is refined iteratively until all parties are satisfied, and then used to start implementing the pipeline to actually provide the data according to the agreed data contract.
它的天然栖息地是 Git 仓库Its Natural Habitat is a Git Repository
但无论数据契约是如何创建的,它最适合存放在 Git 仓库中,与数据产品元数据、用于生成实际数据的代码以及 CI/CD 流水线配置放在一起。契约通常存储在专用子文件夹中,而数据产品 YAML 文件则位于仓库根目录。But regardless of how the data contract is created, its natural habitat is the Git repository alongside its data product metadata, the code that helps to produce the actual data, and the configuration of the CI/CD pipeline. The contracts typically are stored in a dedicated subfolder with the data product YAML being at the root of the repository.
Customers 数据产品的 Git 仓库文件树File tree of the Git repository of the Customers data product
customers.odps.yaml
|- datacontracts
|- customers_pii_snowflake_v1.odcs.yaml
|- customers_pii_snowflake_v2.odcs.yaml
|- customers_npii_snowflake_v1.odcs.yaml
|- code
|- pipeline.sql
.gitlab-ci.yml
我们的建议是不要把它们放在离管道代码太远的地方,因为管道代码通常需要随着数据契约一起变更。而会一起变更的内容应该放在一起。Our advice is to not place them far away from the pipeline code, as the code for the pipeline typically has to change together with the data contract. And things that change together should be put together.
你可能已经注意到了文件名的命名规范。文件名以数据契约的人类可读 ID 开头,其中标明了数据集(customers_pii 或 customers_npii)以及供消费者使用数据的平台(snowflake),后面接主版本号(v1 或 v2)。主版本号属于文件名的一部分,但不属于 ID:不同主版本共用同一个 ID,因此可以作为独立文件并存。这是最佳实践,因为数据产品可以通过不同形式、不同版本以及不同平台提供数据。测试、预发布和生产等不同环境,最好通过数据契约中的单独服务器条目来表示。You might have noticed the naming convention for the filename already. It starts with the human-readable ID of the data contract, which names the dataset (customers_pii or customers_npii) and the technology (snowflake) where the data is available for the consumer, followed by the major version (v1 or v2). The major version is part of the filename, but not of the ID: the ID stays the same across major versions, so they can live side by side as separate files. This is best practice as a data product can offer its data in different forms, versions, and on different technologies. Different environments such as test, staging, and production, are best encoded within the data contract through separate server entries.
版本管理与破坏性变更的故事The Story of Versioning and Breaking Changes
数据契约的主要目标之一,是在消费者受到影响之前发现破坏性变更,并提供平稳的演进流程。为此,数据契约采用语义化版本(SemVer)方案。One of the main goals of data contracts is to find breaking changes before consumers are affected, and offer graceful evolution processes. For that, data contracts follow the SemVer versioning scheme.
- 主版本变更:破坏性变更,例如删除列或重命名列Major Version Change: Breaking change such as removing a column or renaming it
- 次要版本变更:非破坏性变更,例如添加新列Minor Version Change: Non-breaking change such as adding a new column
- 补丁版本变更:小幅变更,例如修正拼写错误或更新支持渠道。Patch Version Change: Small change such as fixing a typo or updating the support channels
破坏性变更会提升主版本号,而非破坏性变更或小幅修复会提升次版本号或补丁版本号。主版本号与其所保护的数据集绑定。发生重大破坏性变更时,应以递增后的主版本号提供数据契约,并同时提供一个新数据集。这样就可以在现有主版本旁逐步引入新的主版本,经过一段宽限期后,再逐步淘汰旧主版本。在宽限期内,状态会告知使用方该版本正处于逐步引入、活跃使用还是逐步淘汰阶段。数据契约通常以草稿状态开始其生命周期,随后作为开发中的版本逐步引入;当其中的承诺正式生效时,则标记为活跃状态。淘汰时也遵循同样的流程,先标记为已弃用,再标记为已退役。生命周期与版本管理紧密交织在一起。当契约作为数据产品的一部分进行管理时,其生命周期通常会遵循数据产品的发布流程,每个主版本都作为独立的输出端口提供,并行运行。Breaking changes increase the major version, whereas non-breaking changes or small fixes increase the minor or patch version. The major version is tied to the dataset it protects. In case of a major, breaking change, the data contract should be provided in an incremented major version alongside a new dataset. This allows phasing in a new major version next to an existing one, and after some grace period, phasing out the old major version. During that grace period, the status signals to the consumer whether it is being phased in, active, or being phased out. The data contract typically begins its life in the draft status, phasing in as being in development, and marked as active if the promises are now actually binding. The same holds for phasing it out, marking it as deprecated and then retired. The lifecycle is heavily intertwined with the versioning. When contracts are managed as part of a data product, this lifecycle often follows the data product's release process instead, with each major version offered as its own output port running in parallel.
对于事件流,这对应于模式注册表的兼容模式。次版本必须向前兼容,这样现有消费者就能继续使用已有的模式读取新事件;理想情况下还应完全兼容,这样新消费者也能重放旧事件。注意注册表的默认设置:向后兼容允许删除字段,而这恰恰会破坏现有消费者。任何会被注册表拒绝的变更都属于主版本变更,应发布到一个新主题中。For event streams, this maps onto the compatibility modes of a schema registry. A minor version has to be forward compatible, so existing consumers keep reading new events with the schema they already have, and ideally fully compatible, so new consumers can also replay old events. Beware of the registry default: backward compatibility permits deleting a field, which is exactly the change that breaks existing consumers. Anything the registry would reject is a major version, published as a new topic.
“Select *”的问题The Problem With “Select *”
著名的“SELECT *”让 SQL 查询编写起来很容易,但也非常脆弱。如果更改列的顺序,或者在中间或末尾添加新列,查询仍然可以运行,但由于结果发生了变化,任何下游依赖都可能因此失效。消费者应当采用“宽容读取者”(Tolerant Reader)模式,只选择自己需要的列。因此,为了保持接口稳定,通常会排除“SELECT *”操作符,这样我们就可以将向表中添加新列定义为一项不会造成破坏性影响的变更。The famous “SELECT *” makes SQL queries easy to write, but also very brittle. If you change the order of the columns, or add a new column, either in between or at the end, the query still runs, but as the result is different, any downstream dependency might break. Consumers should rather act as a Tolerant Reader and select only the columns they need. That's why, for the sake of interface stability, the “SELECT *” operator is typically excluded, so we can define adding a new column to a table as a non-breaking change.
自动化一切Automate All The Things
无人检查的数据契约不过是纸老虎:它的承诺和一页维基页面相比毫无价值,而一旦消费者发现它被违背,信任便荡然无存。真正的价值来自在其之上的自动化,而这其中蕴藏着巨大的潜力:A data contract that nobody checks is a paper tiger: its promises are worth no more than a wiki page, and the first time a consumer finds one broken, their trust is gone. The real value comes with automation on top of it, and the potential is huge:
- 生成 HTML 文档,并在您的内网中统一提供。Generate HTML documentation and make it centrally available in your intranet
- 发布到元数据存储库,例如数据产品市场或数据目录。Publish to metadata repositories such as data product marketplaces or data catalogs
- 在拉取请求的 CI/CD 流水线中,使用测试环境中的数据对照契约进行测试,并在测试失败时阻止合并。Test the data in your test environment against the contract within your CI/CD pipeline in your pull request and prevent a merge in case of failure
- 每天在生产环境中根据契约测试数据,并在承诺遭到违背时通知所有者和所有下游消费者。Test the data in your production environment against the contract every day and inform the owner and any consumer downstream in case of broken promises
- 根据数据契约生成用于创建表的 SQL DDL,作为数据提供方,从设计上确保这些表符合契约要求。Generate the SQL DDL to create the tables from the data contract, making the tables contract-compliant by design as the data provider
- 根据合同推导数据平台上的脱敏和访问策略,例如,对无权访问个人数据的角色,屏蔽所有标记为 pii:true 的列。Derive masking and access policies on the data platform from the contract, for example masking every column tagged
pii:truefor roles without access to personal data - 生成一个 SQL 查询,在不使用 SELECT * 运算符的情况下,以能够容忍数据变化的数据消费者的方式实际使用这些数据。Generate the SQL query to actually use the data as a tolerant data consumer without the select star operator
- 在拉取请求中比较数据契约的新旧版本;如果仅升级次版本号或修订版本号却引入了不兼容变更,则使检查失败。Compare the new version of a data contract with its old one in a pull request and fail if there is a breaking change for only a minor or patch version update
- 在新数据到达使用者之前,先根据契约对其进行验证,并像隔离模式那样扣留违反契约的数据。Validate new data against the contract before it reaches consumers, and hold back data that violates it, as in the quarantine pattern
开源工具 Data Contract CLI 每月下载量超过 100 万次,原生支持 ODCS 格式的数据契约,可用于自动化完成上述所有任务。它在《Thoughtworks 技术雷达》(2025 年 11 月)中被评为“试用”级别,尤其适用于依据数据契约验证数据、检测破坏性变更,以及通过 CI/CD 流水线将数据治理落到实处。The open source tool Data Contract CLI, with over 1 million downloads per month, natively understands data contracts in the ODCS format, and is useful to automate all of these listed tasks. It is rated Trial in the Thoughtworks Technology Radar (November 2025), and found especially useful for validating data against its contract, detecting breaking changes, and operationalizing data governance through the CI/CD pipeline.
数据契约应纳入你的 CI/CD 流水线Data Contracts Belong in Your CI/CD Pipeline
数据契约应纳入 CI/CD 流水线,在每次提交发布前进行检查。Data Contract CLI 为每个阶段都提供了相应命令:datacontract lint 用于验证契约,datacontract breaking 用于检测相对于上一版本的破坏性变更,datacontract ci 则会在每个环境中测试数据是否符合契约。只有所有阶段都通过后,流水线才会部署到生产环境,并使用 datacontract publish 将契约发布到市场。Data contracts belong in your CI/CD pipeline, where every commit is checked before it ships. The Data Contract CLI offers a command for each stage: datacontract lint validates the contract, datacontract breaking catches breaking changes against the previous version, and datacontract ci tests the data against the contract in each environment. Only when all stages pass does the pipeline deploy to production and publish the contract to the marketplace with datacontract publish.
图 6:CI/CD 流水线中的数据契约:每次提交时都会检查,并且每晚都会使用生产数据进行测试Figure 6: Data contracts in the CI/CD pipeline: checked on every commit, and tested against production data every night
测试数据集与测试代码Testing Datasets vs Testing Code
测试数据集与测试代码有所不同。测试代码时,我们会选择输入并检查输出。而使用数据时,我们无法选择输入:我们的代码是基于对所接收数据的假设编写的,这些假设必须成立。数据集没有逻辑或行为,但具有一些特征,例如行数、某个可选列中的空值数量,以及数据集是否为最新;我们可以持续测试这些特征,以便快速发现不符合预期的情况。传统上,这类工作由数据质量工具完成,例如 Great Expectations,每种工具都有自己的检查定义语言。借助数据契约,检查项被纳入契约本身,成为使用者可以依赖、甚至自行测试的承诺。工具并不会因此消失:它们正越来越多地从契约中读取检查项并执行检查,Data Contract CLI 就是如此。Testing datasets is different from testing code. When testing code, we choose the inputs and check the outputs. When consuming data, we can't choose the inputs: our code was written with assumptions about the data it receives, and those assumptions must hold. Datasets have no logic or behavior, but they have characteristics, such as their number of rows, how many null values an optional column has, and whether the dataset is up to date, and these can be tested continuously to detect violations quickly. This has traditionally been done with data quality tools, such as Great Expectations, each with its own language for defining checks. With data contracts, the checks move into the contract itself, as promises the consumer can rely on and even test themselves. The tools don't go away: they increasingly read the checks from the contract and run them, as the Data Contract CLI does.
随后,另一条定时流水线会持续监控,按 cron 计划运行 `datacontract test --server prod`,并发布结果,以便在承诺失效的第一时间通知数据提供方和受影响的数据消费者。A second, scheduled pipeline keeps watch afterwards, running datacontract test --server prod on a cron and publishing the results to inform the data providers and affected consumers the moment a promise breaks.
数据契约的成本与收益The Costs and Benefits of Data Contracts
数据契约能带来信任和自动化方面的回报,但并非没有成本,也不值得为每个数据集都编写。智能体会放大这种权衡的两面。Data contracts pay back in trust and automation, but they are not free, and they are not worth writing for every dataset. Agents amplify both sides of this trade-off.
益处The Benefits
当企业的大部分分析数据都由数据契约描述时,就可以根据契约中的承诺自动测试数据。数据质量也可以持续监控;一旦低于承诺的阈值,就能自动触发应对措施。When a large part of an enterprise's analytical data is described by data contracts, the data can be tested automatically against the promises in the contract. Its quality can be monitored continuously, and when it falls below a promised threshold, counter-actions can be triggered automatically.
同样重要的是,由于消费者的预期被明确记录下来,可以自动检测破坏这些预期的变更,例如在 CI/CD 流水线中阻止部署。破坏性变更不再会沿着流水线传播到下游服务,从而大幅提升整个系统的健壮性。At least as important, because consumers' expectations are written down, changes that break them can be detected automatically, for instance to stop a deployment in a CI/CD pipeline. Breaking changes no longer propagate through pipelines into downstream services, which makes the whole system far more robust.
总体而言,数据契约将责任归属转向数据提供方。这有助于建立提供方与使用方、业务部门与 IT 部门之间的信任,并且越来越多地建立人们与代表他们工作的智能体之间的信任。Overall, data contracts shift ownership towards data providers. That builds trust between providers and consumers, between business and IT, and, increasingly, between humans and the agents working on their behalf.
当消费者是智能体时,这些优势都会进一步凸显,因为智能体会按字面理解契约,并以机器速度执行。契约会告知智能体如何安全、正确地采取行动:如何查询数据的模式、如何将其与其他数据集结合的语义、值得信赖的质量保证,以及它获准执行哪些操作的使用条款。Each of these benefits grows when the consumer is an agent, because an agent reads the contract literally and acts on it at machine speed. A contract tells an agent what it needs to act safely and correctly: the schema to query the data right, the semantics to combine it with other datasets, the quality guarantees to trust it, and the terms of use to know what it is allowed to do.
只有通过这种方式,两项能力才变得切实可行:生成数据管道,以及与数据对话。Two capabilities only become practical this way: generating your data pipeline, and chatting with your data.
生成你的数据流水线Generate Your Data Pipeline
数据契约支持规范驱动开发。数据契约是规范的核心:将它与一个插件一起提供给编码智能体,该插件包含用于描述贵公司如何构建数据管道的技能,智能体便几乎可以自动生成整个数据管道。此类生成过程的示例可在 dataproduct.com 上查看。在生成数据管道的过程中,可以根据契约测试数据,形成反馈循环,引导智能体朝正确的方向前进。Data contracts enable spec-driven development. The data contract acts as the core of the specification: fed into a coding agent, alongside a plugin containing skills that describe how data pipelines are built in your company, the agent can generate almost the entire data pipeline automatically. An example run of such a generation is available on dataproduct.com. During the generation of the data pipeline, the data can be tested against the contract, acting as a feedback loop, steering the agent in the right direction.
图 7:编码智能体根据数据契约、技能和数据市场生成数据管道Figure 7: A coding agent generates the data pipeline from the data contract, skills, and the data marketplace
与您的数据对话Chat With Your Data
业务用户希望能够提出“为什么我们本季度的收入增长了?”这样的问题,并在几分钟内得到答案。对于“与数据聊天”来说,难点不在于生成 SQL,而在于生成正确的 SQL。让智能体连接到拥有数百张表、数千个列的数据库后,它就必须猜测各列的语义,以及如何正确地将这些表连接起来。更不用说,它是否有权使用这些数据来回答问题了。Business users want to ask questions like “Why is our revenue up this quarter?” and get an answer within minutes. With “chat with your data”, the hard part isn't generating SQL, it is generating the correct SQL. Point your agent at the database with its hundreds of tables and thousands of columns, and it has to guess the semantics of the columns, and how to join the tables together correctly. And we haven't even talked about whether it is allowed to answer the question with this data.
但在智能体能够正确查询数据之前,它必须先找到数据。数据契约发布到数据市场后,智能体便可以通过 MCP 等方式搜索,从而让数据得以被发现。找到数据后,数据契约便不再让智能体靠猜测行事。它会说明各列的含义,并通过构成上下文层的语义链接,指明如何正确关联数据集。其使用条款会明确说明哪些数据用途是允许的,哪些是不允许的。有了这些保障,“与数据对话”才真正变得值得信赖。But before an agent can query data correctly, it has to find it. Published to a data marketplace that agents can search, for example through MCP, data contracts make data discoverable in the first place. Once found, a data contract stops the guessing. It tells the agent the meaning of the columns, and through the semantic links that form the context layer, how to join datasets correctly. Its terms of use make it clear what is allowed to be done with the data, and what usages are not. With that, “chat with your data” becomes something you can rely on.
成本The Cost
这些都不是免费的。编写和维护数据契约需要时间和精力,契约的负责人也必须兑现其中的承诺。智能体也让这件事的风险更高:面对过时的契约,智能体和面对正确的契约一样自信地采取行动。None of this comes for free. Data contracts take time and effort to write and maintain, and their owners have to keep the promises in them. Agents raise the stakes here too: an agent acts on an outdated contract just as confidently as on a correct one.
这就是为什么你不应该为公司里的所有数据都引入数据契约。这听起来可能像是泛泛而谈的顾问建议,但确实很重要:应聚焦于团队之间共享数据的接口,最好通过数据产品来实现。That's why you should not introduce data contracts for all the data in your company. It may sound like generic consultant advice, but it matters: focus on the interfaces where one team shares data with another, ideally via data products.
另外,不要一次性全面推行数据契约。如果契约不能立即解决实际问题,这样做会显得官僚主义。应从痛点入手:数据质量问题、管道故障或大量沟通不畅。或者,在构建新的用例时,从一开始就用数据契约明确其接口。Also, don't roll out data contracts all at once. That feels like bureaucracy if a contract does not immediately solve an actual problem. Start where it hurts: data quality issues, broken pipelines, or a lot of miscommunication. Or, when a new use case is being built, specify its interfaces with data contracts right from the start.
此外,引入数据契约也是一种文化转变,意味着要承担数据所有权,并作出明确且可验证的承诺。标准和工具固然有所帮助,但团队必须认识到,承担所有权也意味着在出现问题时负起责任。将一切明确下来还可能暴露出所有权缺失的情况,而这需要先在组织层面加以解决。Moreover, introducing data contracts is a cultural change towards ownership of data, with explicit and verifiable promises. The standard and tooling help, but teams have to learn that ownership also means being responsible when something breaks. Making things explicit can also reveal missing ownership, which then has to be fixed in the organization first.
服务提供方通常以功能交付情况作为衡量标准,因此契约可能让人觉得徒增阻力,却收效甚微。以下几项措施会有所帮助:提供平台模板,让编写和测试契约的成本更低;与使用方开展研讨,共同确定他们实际需要的服务级别;在市场中展示每个数据产品的可靠性,让负责任的所有权得到认可;并明确承诺未兑现时由谁负责处理告警。Providers are usually measured on shipping features, so a contract can feel like friction with little payoff. A few things help: platform templates that make writing and testing a contract cheap, workshops with consumers to agree on the service levels they actually need, showing each data product's reliability in the marketplace so that good ownership gets noticed, and making clear who owns the alert when a promise breaks.
成本确实存在,但数据契约能带来丰厚回报:建立信任、实现自动化,并赋能智能体。谨慎引入后,它们很快就能显现成效。The cost is real, but data contracts offer a high payoff through establishing trust, making automation possible, and empowering agents. When introduced with care, they pay off sooner rather than later.
为什么数据契约将无处不在Why Data Contracts Will Be Everywhere
借助 ODCS,数据契约已经有了事实上的行业标准,由 Linux 基金会负责治理,并且围绕它形成了开源工具生态。我们相信,数据契约很快就会成为数据领域的 OpenAPI,正如 OpenAPI 之于如今的 REST API 一样,原因有三:智能体终于让认真编写数据契约变得值得;数据消费者将开始编写自己的数据契约;开放标准则能确保数据契约具有可移植性。With ODCS, data contracts have a de facto industry standard, governed at the Linux Foundation, and open source tooling around it. We believe that soon data contracts will be for data what OpenAPI is for REST APIs today, for three reasons: agents finally make it worthwhile to write them well, consumers will start writing their own, and an open standard keeps them portable.
在智能体时代,正确设计激励积分In the Age of Agents, the Incentive Points the Right Way
即使没有 AI 代理,数据契约也很有价值。但精力都投入到了可以自动化的部分。模式和质量规则都经过了认真完善;而业务名称、描述和使用条款等文字字段,却没有以同样严谨的态度填写,因为它们只供其他人阅读。遗憾,但事实如此。Data contracts are valuable even without AI agents. But the effort goes into the parts that can be automated. Schema and quality rules are filled out with care; the prose fields such as business names, descriptions, and terms of use are not filled out with the same rigor, as they are only read by other humans. Sad, but true.
智能体改变了这一切。智能体会照着这些描述性字段的字面意思行事。描述含糊不清,它就会搭建出错误的数据管道;缺少“使用条款”,它就可能以不该有的方式使用数据;用途不明确,它就会给出自信满满却错误的答案。突然之间,合同中被忽视的那一半有了实际影响,而激励机制终于指向了正确的方向。标准也已经跟上:ODCS 3.2 新增了 AI 上下文,这是专为智能体编写的一个区块。Agents change that. An agent takes those prose fields at their word and acts on them. A vague description leads it to build the wrong pipeline, a missing “terms of use” leads it to use the data in ways it shouldn't, and an ambiguous purpose leads to a confidently wrong answer. Suddenly, the neglected half of the contract has real consequences, and the incentive finally points the right way. The standard is already following: ODCS 3.2 added the AI context, a block written for agents.
过去,元数据是为了别人而做的苦差事,因此总被搁置在待办事项的末尾。如今,它能给你带来回报:提出一个问题,看到错误答案,修改描述或使用条款,再问一次。很少有人愿意为了别人而编写文档,但如果受益的是自己,元数据就会变得更完善。这就是推动力:代理终于让认真写好整份契约变得值得,也正因如此,在代理时代,数据契约将蓬勃发展。Metadata used to be a chore done for other people, so it languished at the bottom of the backlog. Now it pays you back: ask a question, see a wrong answer, fix the description or the terms of use, ask again. Few people write documentation for someone else's benefit, but when the benefit is their own, the metadata gets better. This is the forcing function: agents finally make it worthwhile to write the whole contract well, which is exactly why, in the age of agents, data contracts will flourish.
消费者驱动的数据契约补上了缺失的视角Consumer-Driven Data Contracts Add the Missing Perspective
到目前为止,我们已经了解了由提供方发布的数据契约,以便使用方能够信任数据。但信任也必须是双向的,例如在共享敏感数据时,而这正是使用条款的作用。So far, we have looked at data contracts published by providers so that consumers can trust the data. But trust also has to run the other way, for example when sharing sensitive data, which is what the terms of use are for.
将消费者驱动契约原则应用于数据契约,可以更进一步:消费者也可以发布自己的数据契约,以与我们迄今讨论的提供方一侧相同的结构化方式,说明自己的承诺和预期。事实上,我们可以使用完全相同的 ODCS 定义结构来描述消费者驱动契约,因为改变的只是方向:例如,在提供方驱动契约中,模式定义表达的是一项承诺;而在消费者驱动契约中,它表达的则是一项预期。Applying the principle of consumer-driven contracts to data contracts goes one step further: a consumer can publish their own data contract, specifying their promises and expectations in the same structured way that we looked at the provider side so far. In fact, we can use the exact same ODCS-defined structure to describe a consumer-driven contract, because it is just the direction that changes: whereas for instance a schema-definition in the provider-driven contract states a promise, in the consumer-driven contract, it states an expectation.
这也使得从消费者端采用契约优先模式成为可能:消费者无需知道谁能提供所需数据,就可以先指定需要的数据,再根据该规范查找匹配的数据;如果由 AI 代理执行搜索,这一模式就会尤为强大。消费者驱动的契约还会记录实际使用了哪些数据,并将其与获准访问的数据进行对比,从而帮助提供方优化服务并实现治理自动化。This also allows contract-first from the consumer side: a consumer specifies the data they need without knowing who could provide it, and the specification is used to find matching data, which becomes especially powerful when an AI agent does the search. Consumer-driven contracts also document which data is actually used compared to what access was granted, which helps providers optimize their service and automate governance.
开放标准助力实现元数据主权Open Standards Enable Metadata Sovereignty
元数据的体量虽小,却具有战略核心地位:它是所有宝贵数据的地图,也是每个目录、质量检查、数据血缘工具和 AI 智能体赖以构建的基础。这正是大型供应商乐于免费提供元数据解决方案的原因。这并非出于慷慨,而是因为一旦你的元数据以他们的专有格式存储,所有读取这些数据的东西也都会被锁定。元数据体量如此之小,没有任何存储或成本上的理由要将其封闭在专有格式中。这样做纯粹是为了掌控权。Metadata is tiny in volume but strategically central: it is the map to all your valuable data and the foundation every catalog, quality check, lineage tool, and AI agent builds upon. That is exactly why large vendors are happy to give their metadata solution away for free. It is not out of generosity, but because once your metadata lives in their proprietary format, everything reading it is locked in too. Since metadata is so small, there is no storage or cost reason to keep it proprietary. Doing so is purely a play for control.
开放标准是唯一真正有效的保障。它能让元数据保持可移植性,让你组合使用来自不同供应商的最佳工具,并由不受供应商左右的治理机制管理其格式。ODCS 由 Linux 基金会托管,因此没有任何一家公司能单方面改变规则。先行企业不得不从零开始打造自定义格式和工具,而最近采用 ODCS 的企业则能以极少的投入,立足于 ODCS 及其开放生态系统。判断自己是否被供应商锁定的一个简单方法是:你能否将所有契约导出为纯文件存入 git,并仅凭这些文件在别处重建目录?随着智能体成为元数据的主要使用者,谁掌控其格式,谁就掌控对企业数据的访问。OpenAPI 已经为运营系统展示了另一种选择:它本身就是一种开放的元数据标准,用不受供应商左右的格式描述 REST API,任何网关、生成器或文档工具都能读取。ODCS 将同样的优势带给数据。拥抱开放标准,才能掌握元数据的主权。An open standard is the only real defense. It keeps your metadata portable, lets you combine best-of-breed tools from different vendors, and puts the format under vendor-neutral governance. ODCS lives at the Linux Foundation, so no single company can change the rules. Pioneering companies had to build custom formats and tooling from scratch, while recent adopters build on ODCS and its open ecosystem at a fraction of the effort. A simple test of whether you are locked in: can you export all your contracts as plain files into git and rebuild your catalog elsewhere from them alone? And as agents become the primary consumers of metadata, whoever controls its format controls access to your enterprise data. OpenAPI has already shown the alternative for operational systems: it is itself an open metadata standard, describing REST APIs in a vendor-neutral format that any gateway, generator, or documentation tool can read. ODCS brings the same to data. Those who embrace open standards keep sovereignty over their metadata.