Skip to main content

ValidationSpec

def ValidationSpec(
*,
name: str,
validation_result: Artifact,
optional: bool = False,
) -> ValidationSpec

ValidationSpec.name

ValidationSpec.name: str

Unique name identifying this validation within its ValidationInfo.


ValidationSpec.optional

ValidationSpec.optional: bool

Whether this validation is skipped by default (only run when explicitly enabled via --enable-optional-validations <name>).


ValidationSpec.validation_result

ValidationSpec.validation_result: Artifact

Build artifact produced by the validator. After the producing action runs, Buck2 reads the file as UTF-8 JSON and uses its contents to decide pass/fail.

Expected shape:

{
"version": 1,
"data": {
"status": "success",
"message": "optional human-readable detail"
}
}
  • version (int, required): schema version. Currently 1.
  • data.status (string, required): "success" or "failure".
  • data.message (string, optional): shown to the user; supply on failure so the diagnostic is actionable.

Additional fields outside the required ones are tolerated and ignored by Buck2 — both at the top level (alongside version / data) and inside data (alongside status / message). This is a deliberate extension point: attach debug or diagnostic info (e.g. data.duration_ms, data.tool_version, links to a build dashboard) that you want carried with the verdict.

Buck2 surfaces three distinct errors if the file does not conform: invalid JSON, incompatible schema version, or schema mismatch. Source artifacts are rejected — the result must come from an action.

See Writing the validator in the Validations guide for end-to-end examples.