Skip to content

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

Description

@dhruvraajeev

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:

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions