4.2.9 OutputGroupInfo & Output Groups

recommended

OutputGroupInfo gives a rule a second way to publish files: not as the target's default build result, and not as a semantic provider for downstream rules, but as named groups that users and tools can request when they need a specific slice of the target's outputs.1 It is the rule-authoring answer to "this target can produce more files than I want from every normal bazel build."

Publish each rule output on the surface that matches its consumer
Ask who needs each artifact: normal builds, tools, dependent rules, or automatic validation.
Rule target
//pkg:app_bundle produces several artifacts
analysis chooses how each is published
bundle.zip main

The ordinary build result

debug.json metadata

Tools can request the file. A provider gives it semantic meaning.

lint.txt report

Useful on demand, noisy by default

validation.marker check

A marker for an execution-phase validation action

DefaultInfo.files
Normal build result
requested by bazel build
files = depset([bundle.zip])
OutputGroupInfo
Named request surfaces
for users, CI, IDEs, aspects
debug_files lint_reports
--output_groups=+debug_files
Custom provider
Rule-to-rule meaning
dependency contract, not a download knob
BundleDebugInfo schema_version
_validation group
Default validation request
runs without becoming an action input
_validation = depset([validation.marker])
Output groups let humans and tools request files. --output_groups=name replaces defaults while --output_groups=+name adds to them.

Default Outputs Are Not Every Output

When a user runs bazel build //pkg:target, Bazel does not run every action the rule declared. It runs the actions needed for the requested output files and their transitive action dependencies.2 DefaultInfo(files = ...) chooses the ordinary output set for that command-line request. If a rule does not return DefaultInfo or omits files, Bazel falls back to all predeclared outputs.3

That boundary is useful. A library rule may produce a compiled archive as its default output, but also produce debug symbols, diagnostics, generated manifests, or machine-readable reports. If all of those files go into DefaultInfo.files, every normal build gets heavier. If none of them go into a default output or output group, their actions may never run when the target is built directly, because no requested artifact reaches them.4

Output groups sit between those two extremes. An output group is a named set of files that can be requested explicitly from a BUILD file through filegroup or from the command line with --output_groups.5 For rule authors, the Starlark surface is the built-in OutputGroupInfo provider.

Declaring Named Groups

OutputGroupInfo is unusual among built-in providers because its constructor accepts arbitrary keyword names. Each keyword becomes one output group, and the value is a depset of File objects.6

def _bundle_impl(ctx):
    bundle = ctx.actions.declare_file(ctx.label.name + ".zip")
    debug_manifest = ctx.actions.declare_file(ctx.label.name + ".debug.json")
    lint_report = ctx.actions.declare_file(ctx.label.name + ".lint.txt")

    ctx.actions.run(
        executable = ctx.executable._packager,
        inputs = ctx.files.srcs,
        outputs = [bundle, debug_manifest],
        arguments = [bundle.path, debug_manifest.path],
    )
    ctx.actions.run(
        executable = ctx.executable._linter,
        inputs = ctx.files.srcs,
        outputs = [lint_report],
        arguments = [lint_report.path],
    )

    return [
        DefaultInfo(files = depset([bundle])),
        OutputGroupInfo(
            debug_files = depset([debug_manifest]),
            lint_reports = depset([lint_report]),
        ),
    ]

Now the default build asks for the bundle:

bazel build //pkg:app_bundle

A developer or tool that wants only the debug manifest can request that group:

bazel build //pkg:app_bundle --output_groups=debug_files

That unprefixed form replaces the normal default output request. To build the ordinary bundle and the debug manifest in one invocation, add the group with +:

bazel build //pkg:app_bundle --output_groups=+debug_files

A misspelled group name does not fail the build. If no top-level target or aspect provides the requested group, Bazel 9.x succeeds silently without building those files. Bazel 10 prints WARNING: Output group 'debug_flies' was requested, but was not present on any top-level target or aspect. Its new --incompatible_fail_on_unknown_output_groups flag, listed for flipping in a future major release, turns that warning into an error.7,8 A CI job or IDE integration that depends on a group should check that the expected files actually appeared.

The BUILD-file request surface is filegroup. This gives the selected group an ordinary target label, which is useful when a package wants a named handle for a generated report without changing the producing rule's default outputs.5

filegroup(
    name = "app_bundle_debug_files",
    srcs = [":app_bundle"],
    output_group = "debug_files",
)

The key design point is that output groups are request surfaces, not dependency contracts. Do not use OutputGroupInfo to convey specific file categories to the actions of consuming rules. Define a rule-specific provider for that instead.9 If another rule needs the debug manifest as an input, publish a custom provider from 4.2.7 Custom Provider Declaration. If a human, CI job, IDE, or aspect result needs to ask Bazel to build and download that file category, use an output group.

Output Groups Fit Tooling

Named groups are especially useful when the consumer is outside the normal dependency graph. cquery --output=files reports only files advertised in the requested output groups, and the Starlark cquery API can inspect target.output_groups. The official cquery docs show reading target.output_groups.compilation_outputs for a cc_library.10 That is the tooling side of the same contract: the rule advertises named files, and a tool chooses which group to request or inspect.

Aspects also participate in this model. A rule target and an aspect applied to that target may both return OutputGroupInfo, and Bazel merges the resulting providers as long as they do not define the same group names.11 That is why aspect-generated lint reports, IDE metadata, or source indexes usually land in output groups rather than in the target's default outputs. The broader aspect design belongs in 4.8.2 Aspect Implementation Basics. Here the rule-authoring lesson is simpler: choose group names as part of the public tooling API.

rules_pyrefly, a type-checking aspect for existing py_* targets, shows both the producing and the requesting side in one small ruleset. Its aspect returns only OutputGroupInfo: a pyrefly group holding each target's diagnostics, plus a debug-only pyrefly_input group exposing the JSON it feeds the checker, so a user can inspect what the aspect computed without reverse-engineering the action. The recommended build:pyrefly config pairs --aspects with --output_groups=pyrefly. That unprefixed form is deliberate. With +pyrefly, Bazel also builds the requested targets' normal outputs, so an unrelated build failure would break a type-check-only run.12

For debugging, output groups are adjacent to the query tools from 5.2.2 bazel cquery — Configured Graph and 5.2.3 bazel aquery — Action Graph. cquery can show which group files a configured target exposes. aquery shows the actions that produce those files once they become requested outputs. Use both when a report exists in the provider but does not appear in the build result.

Consumer Side: A Compile-Only CI Gate

Output groups also let a CI job ask for less than a normal build. Plaid's merge queue had to catch pull requests that each passed CI alone but broke the build once merged together. Those breaks were almost always Go compile errors and rarely test failures. Building every affected target overloaded their CI runners and remote cache, so the gate asks only for compiled packages:13

bazel build //lib/foo/... --output_groups=compilation_outputs

On a sample package with one go_library, one go_binary, and one go_test, the plain build ran 23 actions and produced 4.6 MB, mostly the linked binary and test binary. The compile-only request ran 10 actions and produced 58 KB: package archives for the library, the binary's own package, and the test's internal and external test packages.14 The unprefixed --output_groups form replaces the default outputs, so nothing is linked. Validation actions still run, because _validation is requested regardless of --output_groups.15

Before relying on such a gate, check three things:

  • What it cannot see. Nothing is linked and no test runs, so failing tests and link-time errors such as missing symbols pass the gate. Plaid accepted that trade because its merge breaks were compile errors.13 The gate complements a full build-and-test run. It does not replace one.
  • The group name for each ruleset. Each rule picks its own group names. rules_go uses compilation_outputs, and the official cquery docs read a group of that name from a cc_library.13,10 Do not assume other rulesets follow it. A target that lacks the requested group silently adds nothing to the build. The Bazel 10 warning described above fires only when no top-level target provides the group. List what the gate will build per target kind with bazel cquery //lib/foo:all --output=files --output_groups=compilation_outputs.10,7
  • Whether the group covers test sources. In rules_go, go_test left its external test package, the *_test.go files that declare package foo_test, out of compilation_outputs from the group's introduction in 2018 until Plaid's fix. Compile errors in those files passed a compile-only gate unnoticed.13,16 The fix, rules_go#4437, first shipped in rules_go v0.58.0.16 On older releases, and on any ruleset you have not checked, break a test file on purpose and confirm that the gate fails.

Treat the group as a contract you have tested, not a name you guessed.

Validation Actions Use A Special Group

Validation actions are the most important special case. The validation-layer decision — when a check belongs in attr.*, fail(), provider init, or an execution action — is covered in 4.2.4 Error Handling & Validation. This article only needs the output-group part: artifact-content checks often produce a marker or report that is not an input to the main build artifact.17

Bazel's documented solution is the special _validation output group. A rule puts the validation action's marker output in OutputGroupInfo(_validation = depset([validation_output])). The marker does not go into DefaultInfo and should not be added as an input to unrelated actions.18,19

return [
    DefaultInfo(files = depset([main_output])),
    OutputGroupInfo(_validation = depset([validation_marker])),
]

The _validation group is special because Bazel requests its outputs by default whenever the target builds, alongside DefaultInfo.files and regardless of --output_groups.15 That means the validation marker does not need to be wired into another action's inputs to run. The rule can keep validation effects out of consumer actions while still guaranteeing the check happens on a normal build. The behavior has documented limits: validation actions are skipped when the target is reached as a tool, through an implicit dependency such as a private _tool attribute, or in the exec configuration, and the whole feature can be disabled with --run_validations=false.20,21 Within those rules, normal caching applies — if the validation action's inputs have not changed and the action previously succeeded, Bazel does not rerun it.15

This makes validation actions a built-in quality gate for a rule. If the check is intrinsic to the rule's correctness, put it in _validation. If an infrastructure team wants to overlay checks across many existing rules without changing those rules, the decision moves toward aspects and the trade-off in 4.8.3 Validation Actions vs Aspects.22

Naming Is API Design

Output group names become strings that users, CI scripts, IDEs, and aspects may depend on. Keep them stable and descriptive: debug_files, lint_reports, source_maps, ide_info. Avoid using an output group as a dumping ground for every non-default file. A group should represent one request someone can explain.

Also avoid over-promising transitive semantics. If a group contains only this target's local report, name it locally. If it intentionally aggregates reports from dependencies, build that aggregation explicitly with depsets and document the behavior. The same collection discipline from 4.1.5 depset vs list applies here because output group values are depsets too.

The mini-ruleset's OutputGroupInfo publishes a direct manifest, a transitive manifest rollup, and the special _validation marker without adding those files to the target's normal default output set.

key takeaway

Use DefaultInfo.files for the files a normal build of the target should produce. Use custom providers for files and metadata that dependent rules need as a semantic contract. Use OutputGroupInfo for named artifact sets that users and tools can request selectively.

The special _validation group is the exception with scheduling semantics: it makes execution-phase checks run without wiring their marker outputs into unrelated actions.

On the consumer side, a ruleset's compile-only group can make a fast CI gate, once you have checked its name and that it covers test sources. It still misses link and test failures.

Check your understanding · 4 questions

1.Match each output-group request surface to what it asks Bazel to build.

Drag each answer onto the matching prompt, or click an answer and then click a prompt

Answers
bazel build //pkg:app_bundle
bazel build //pkg:app_bundle --output_groups=debug_files
bazel build //pkg:app_bundle --output_groups=+debug_files
filegroup(srcs = [":app_bundle"], output_group = "debug_files")

2.Which are good uses of OutputGroupInfo?

Select all that apply

3.True or false: validation actions and output groups.

Choose True or False for each sentence

_validation outputs are requested alongside normal target outputs in ordinary builds, with documented skip cases such as tool and exec-configuration dependencies.
Validation marker outputs should be added as inputs to the main compile action so Bazel knows to run them.
--run_validations controls whether validation actions run, and defaults to true.
--output_groups=+debug_files requests debug_files in addition to the target's normal default outputs.

4.A Go monorepo adds bazel build //... --output_groups=compilation_outputs as a fast merge-queue gate. Which statements are true?

Select all that apply

0 of 4 answered

Footnotes

  1. OutputGroupInfo — provider definition for rule output groups. ↩

  2. Rules — requested files determine which reachable actions execute. ↩

  3. DefaultInfo — files field and fallback to predeclared outputs. ↩

  4. Frequently Asked Questions — unrequested output actions do not execute unless the file is requested directly, via an output group, or through default outputs. ↩

  5. Bazel Glossary — output group definition and command-line / filegroup request surfaces. ↩1 ↩2

  6. Rules — OutputGroupInfo accepts arbitrary group names as keyword arguments. ↩

  7. Bazel 10.0.0rc1 release notes — --incompatible_fail_on_unknown_output_groups is listed among flags to be flipped in a future major release. ↩1 ↩2

  8. Bazel — core implementation, documentation, and regression corpus — verified with --output_groups=+debug_flies. 10.0.0rc2 prints the quoted warning, or an error with the flag set. 9.3.1 builds without any message. The flag defaults to false in 10.0.0rc2. ↩

  9. Rules — output groups should not replace rule-specific providers for consumer actions. ↩

  10. Configurable Query (cquery) — files output respects --output_groups. Starlark example reads target.output_groups.compilation_outputs. ↩1 ↩2 ↩3

  11. Rules — rule and aspect OutputGroupInfo providers are merged when group names do not collide. ↩

  12. rules_pyrefly — pyrefly/private/pyrefly.bzl returns OutputGroupInfo(pyrefly = ..., pyrefly_input = ...); docs/integration.md calls pyrefly_input a debug-only group for inspecting the generated input JSON; the README and docs/users.md recommend --output_groups=pyrefly over +pyrefly for type-check-only runs, because the + form also builds normal target outputs and can surface unrelated build failures. Checked on main on 2026-12-04 ↩

  13. Build less, merge faster: avoiding diamond merges with a merge queue — Second attempt and Key optimization: compile-only validation: merge breaks were mostly Go compile errors, --output_groups=compilation_outputs skips linking, and the go_test gap in that group dating from 2018. ↩1 ↩2 ↩3 ↩4

  14. Build less, merge faster: avoiding diamond merges with a merge queue — before/after comparison for //lib/foo/...: 23 vs 10 actions, 4.6M vs 58K output size, with per-file sizes. ↩

  15. Rules — _validation outputs are always requested while normal caching and incrementality still apply. ↩1 ↩2 ↩3

  16. rules_go — canonical Go rules and toolchain integration for Bazel — bazel-contrib/rules_go#4437 ("Include blackbox tests in compilation_outputs group") merged on 2025-09-02. It adds the external test archive to the group. The v0.58.0 release notes are the first to list it (v0.57.0 does not). Checked on GitHub on 2026-12-03. ↩1 ↩2

  17. Rules — validation actions run checks that require artifacts during execution. ↩

  18. Validation actions: correct builds off the critical path — historical dummy-output workarounds and critical-path cost. ↩

  19. Rules — _validation output group example and guidance not to add validation outputs to other action inputs. ↩

  20. Rules — documented cases where validation actions are not run. ↩

  21. Rules — --run_validations controls validation actions and defaults to true. ↩

  22. Validation actions: correct builds off the critical path — Q&A comparing validation actions with aspects and their overhead. ↩