Skip to content

feat(workflows): add from_json expression filter#2961

Open
doquanghuy wants to merge 1 commit into
github:mainfrom
doquanghuy:feat/2960-from-json-filter
Open

feat(workflows): add from_json expression filter#2961
doquanghuy wants to merge 1 commit into
github:mainfrom
doquanghuy:feat/2960-from-json-filter

Conversation

@doquanghuy

Copy link
Copy Markdown
Contributor

Description

Fixes #2960.

Adds one arg-less pipe filter to the sandboxed expression evaluator:

items: "{{ steps.emit.output.stdout | from_json }}"

_filter_from_json parses a JSON string into its typed value (list/dict/scalar). Semantics are parse-or-raise: invalid JSON or non-string input raises a clear ValueError — never a silent passthrough, since a parse failure means the pipeline wiring is wrong and silence would hide it. The module docstring's filter list is updated; no other filter or evaluator behavior is touched.

This is the smallest unblock for feeding fan-out items: (or any condition/arg) from a step that computes a collection at runtime. It composes with — and doesn't preclude — a future declared-outputs: mechanism, which I'm proposing separately.

Testing

  • Ran existing tests with uv sync && uv run pytesttests/test_workflows.py 210 passed
  • Three new tests in TestExpressions (valid JSON → typed value; invalid JSON raises; non-string raises) — all three are red against current main, green with the filter (verified both directions)
  • uvx ruff check src/ — clean
  • Tested locally with uv run specify --help
  • Tested with a sample project (covered by the evaluator tests; exercised manually with the [Bug]: fan-out silently coerces a non-list 'items' to [] — zero-instance runs with no error #2956 repro workflow rewired through | from_json)

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (describe below)

Code, tests, and this description were authored with AI assistance (Claude); verified by running the repo's test suite and ruff locally in both red and green directions.

Step outputs captured as strings could never become typed values in
templates - the filter set was default/join/map/contains only, so e.g.
a fan-out items: could never consume a step's JSON stdout. Add an
arg-less from_json pipe filter with parse-or-raise semantics: invalid
JSON or non-string input raises a clear ValueError rather than passing
through silently.

Fixes github#2960
@doquanghuy doquanghuy requested a review from mnriem as a code owner June 12, 2026 17:29
@doquanghuy

Copy link
Copy Markdown
Contributor Author

@mnriem when you have a moment, would appreciate a review — happy to adjust anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: a from_json expression filter so step outputs can become typed values

1 participant