#1327·chaosblade

[blade-ai] --output silently ignores invalid formats / falls back to JSON

Author: dhruvraajeevCreated Jul 21, 2026Updated Jul 27, 2026

What

Every blade-ai CLI command exposes --output/-o with help text json|yaml, but the value is an unvalidated str passed to format_output() in blade-ai/src/chaos_agent/cli/output.py:

python
if output_format == "yaml" and HAS_YAML:
    return yaml.dump(...)
else:
    return json.dumps(...)

So any unrecognized format silently returns JSON — --output xml, --output ymal (typo), etc. produce JSON with no error and no warning. The same silent fallback happens for --output yaml if PyYAML is somehow unavailable.

Affected commands (8)

config, capabilities_cmd, list_cmd, metric, confirm, inject, version, recover — each declares:

python
output: str = typer.Option("json", "--output", "-o", help="Output format: json|yaml")

Why it matters

A user scripting against the CLI who typos --output or requests an unsupported format gets JSON back silently, with no signal that their flag was ignored. For a tool whose output is consumed by automation, silently ignoring an invalid flag is a correctness problem.

Proposed fix

  • Add an OutputFormat(str, Enum) in cli/output.py and type the --output option as that enum across all 8 commands, so Typer rejects invalid values at the CLI boundary and auto-generates accurate help.
  • Make format_output() validate defensively: raise a clear ValueError on an unknown format, and a clear "install pyyaml" error when yaml is requested but PyYAML is unavailable (PyYAML is a declared dependency, so this only fires on a broken install).

Single, self-contained change (one helper + option typing + tests). Happy to submit a PR. (Observed on commit c571faa.)

Environment: blade-ai v0.3.0

Source: chaosblade-io/chaosblade