← Back to Pull requests

Preserve JSON Schema references in flow parameters #23432

Open
ska2704 opened this pull request with 121 lines diff across 2 files
View on GitHub
ska2704 ska2704 commented on Oct 18, 2026 08:34 UTC
Author

closes #15763

This PR preserves non-block $ref values in flow parameters. A schema containing #/$defs/Item currently fails with ParameterTypeError before the flow runs, including when the schema is nested inside a Pydantic model. Local paths, relative references, URLs and non-UUID URNs now pass through as parameter data.

UUID objects, all strings accepted by the UUID parser, and dictionaries containing block_document_id or block_document_slug still reach Block.load_from_ref. This preserves direct UUID-URN block references and errors for malformed explicit block IDs. UUID-parseable schema references retain their existing block interpretation; this change does not introduce a separate schema discriminator. The validate_parameters docstring records that boundary.

<details>
<summary>Validation</summary>

  • The direct urn:uuid: and uuid: block regressions pass on the merge base (87b5243), fail on the previous PR head (f4fdb44), and pass with this revision.

  • The original five schema regressions fail on unchanged upstream with block-resolution errors.

  • uv run pytest tests/blocks/test_block_reference.py tests/test_flows.py -q -n 4: 402 passed, 11 existing skips, 2 expected failures.

  • uv run pytest tests/typesafety/test_flows.yml -q: 6 passed.

  • uv run pre-commit run --files src/prefect/flows.py tests/blocks/test_block_reference.py: all applicable hooks passed.
  • Coverage includes direct and explicit UUID/URN block references, slug references, malformed explicit block IDs, non-block schema references, and schemas inside models passed to sync and async flows. Tests use the local test server; no Prefect Cloud account is needed.

    </details>

    Checklist

  • This pull request references any related issue by including "closes <link to issue>"

  • - If no issue exists and your change is not a small fix, please create an issue first.
  • If this is a complex change, a maintainer has confirmed the proposed approach on the linked issue.

  • If this pull request adds or changes functionality, it includes tests or explains why tests are not needed.

  • If this pull request changes user-facing behavior, it updates documentation or explains why documentation is not needed.

  • If this pull request removes docs files, it includes redirect settings in mint.json.

  • If this pull request adds functions or classes, it includes helpful docstrings.
  • Diff: 121 lines (+108 / -13) across 2 files Reviewer: ska2704 Review duration: 8485m
    All Vouch review confidence checks passed
    Residual risk 0.07 = Change Risk (0.47) × (1 − Review Confidence (0.85)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 121 lines diff across 2 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.94 · 5 substantive comment(s)
    0.94
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    84%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.287
    Self Review self_review
    0.140
    Real PR Conversation Timeline
    16 items
    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Oct 18, 2026 08:35 UTC
    Code Review
    src/prefect/flows.py:1
    @@ -601,11 +605,24 @@ def validate_parameters(self, parameters: dict[str, Any]) -> dict[str, Any]:
             """
     
             def resolve_block_reference(data: Any | dict[str, Any]) -> Any:
    -            if isinstance(data, dict) and "$ref" in data:
    -                from prefect.blocks.core import Block
    +            if not isinstance(data, dict) or "$ref" not in data:
    +                return data
    +
    +            ref = data["$ref"]
    +            if isinstance(ref, str):
    +                try:
    +                    UUID(ref)
    +                except ValueError:
    +                    return data

    <!-- devin-review-comment {"id": "BUG_pr-review-job-a0f810747a7f47cb84fa636e61acbb88_0001", "file_path": "src/prefect/flows.py", "start_line": 613, "end_line": 614, "side": "RIGHT", "based_on_repo_rules": false, "kind": "bug"} -->

    🟡 UUID URI references abort schema flows

    When a schema uses urn:uuid:... in $ref, UUID(ref) treats it as a block ID. Without a matching saved block, Block.load_from_ref aborts the flow before it can use the schema.

    <details>
    <summary>Learn more</summary>

    A JSON Schema $ref is a URI reference, so it can legally contain a UUID URN. Python's UUID constructor accepts urn:uuid:..., but Block.load_from_ref interprets that same string as a saved block ID and raises when no block exists. The flow therefore fails before its body receives a valid schema.

    Example: A flow receives {"properties": {"item": {"$ref": "urn:uuid:12345678-1234-1234-1234-123456789abc"}}}. Validation queries for a block with ID 12345678-1234-1234-1234-123456789abc instead of passing the schema to the flow.

    Recommended fix: Distinguish explicit block-reference syntax from URI references before invoking Block.load_from_ref. If plain UUID strings must remain supported, constrain that path to the serialized block-ID form and treat urn:uuid: as schema data; add a regression covering UUID URNs.

    </details>

    <!-- devin-review-badge-begin -->
    <a href="https://app.devin.ai/review/prefecthq/prefect/pull/23432" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
    <!-- devin-review-badge-end -->

    ---
    Was this helpful? React with 👍 or 👎 to provide feedback.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on Oct 18, 2026 08:35 UTC
    Reviewer

    [!NOTE]

    Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

    Devin Review found 1 potential issue.

    <!-- devin-review-badge-begin -->
    <a href="https://app.devin.ai/review/prefecthq/prefect/pull/23432" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
    <!-- devin-review-badge-end -->

    ska2704 ska2704 commented on code on Oct 18, 2026 08:41 UTC
    Code Review
    src/prefect/flows.py:1
    @@ -601,11 +605,24 @@ def validate_parameters(self, parameters: dict[str, Any]) -> dict[str, Any]:
             """
     
             def resolve_block_reference(data: Any | dict[str, Any]) -> Any:
    -            if isinstance(data, dict) and "$ref" in data:
    -                from prefect.blocks.core import Block
    +            if not isinstance(data, dict) or "$ref" not in data:
    +                return data
    +
    +            ref = data["$ref"]
    +            if isinstance(ref, str):
    +                try:
    +                    UUID(ref)
    +                except ValueError:
    +                    return data

    Fixed in f4fdb44. String references containing a URI scheme now stay as parameter data before UUID parsing. Added regressions for both urn:uuid:... and uuid:...; each reproduced the block-resolution failure before the guard. An explicit block_document_id dictionary containing a UUID URN still loads its saved block.

    The block-reference and flow suites pass: 401 passed, 11 skipped, 2 xfailed. Flow typing checks pass all 6 tests, and the applicable pre-commit hooks pass.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Oct 18, 2026 08:42 UTC
    Code Review
    src/prefect/flows.py:1
    @@ -601,11 +605,24 @@ def validate_parameters(self, parameters: dict[str, Any]) -> dict[str, Any]:
             """
     
             def resolve_block_reference(data: Any | dict[str, Any]) -> Any:
    -            if isinstance(data, dict) and "$ref" in data:
    -                from prefect.blocks.core import Block
    +            if not isinstance(data, dict) or "$ref" not in data:
    +                return data
    +
    +            ref = data["$ref"]
    +            if isinstance(ref, str):
    +                try:
    +                    UUID(ref)
    +                except ValueError:
    +                    return data

    ✅ Resolved: The colon guard now preserves UUID URNs as schema data, preventing the prior schema-flow failure. The current finding concerns the opposite case: a UUID URN intentionally supplied as a saved-block reference is no longer resolved.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Oct 18, 2026 08:42 UTC
    Code Review
    src/prefect/flows.py:1
    @@ -601,11 +605,26 @@ def validate_parameters(self, parameters: dict[str, Any]) -> dict[str, Any]:
             """
     
             def resolve_block_reference(data: Any | dict[str, Any]) -> Any:
    -            if isinstance(data, dict) and "$ref" in data:
    -                from prefect.blocks.core import Block
    +            if not isinstance(data, dict) or "$ref" not in data:
    +                return data
    +
    +            ref = data["$ref"]
    +            if isinstance(ref, str):
    +                if ":" in ref:
    +                    return data

    <!-- devin-review-comment {"id": "BUG_pr-review-job-578700d7bdd746d0bbef6ec5bb1b46da_0001", "file_path": "src/prefect/flows.py", "start_line": 613, "end_line": 614, "side": "RIGHT", "based_on_repo_rules": false, "kind": "bug"} -->

    🔴 UUID URN block references stop loading

    When a flow receives {"$ref": block_id.urn}, resolve_block_reference preserves the dictionary instead of loading the block. Block's ID reader accepts URNs through UUID, so block parameters now fail validation.

    <details>
    <summary>Learn more</summary>

    A flow parameter can use a saved block document's UUID string as its $ref. Python's UUID() also parses the ID's urn:uuid: and uuid: forms. Block's ID reader uses that parser, so it can load those references. The colon guard returns the original dictionary before block loading, and a flow parameter annotated with a Block then fails validation.

    Example: Save a ParamBlock with ID 12345678-1234-1234-1234-123456789abc. Passing {"$ref": "urn:uuid:12345678-1234-1234-1234-123456789abc"} to a flow with a ParamBlock parameter now leaves $ref as input rather than loading that block.

    Recommended fix: Distinguish schema URI references from block references without excluding UUID URNs recognized by Block.load_from_ref. Add a direct $ref URN block test alongside the existing dictionary block_document_id URN test, while retaining the schema URI preservation test.

    </details>

    <!-- devin-review-badge-begin -->
    <a href="https://app.devin.ai/review/prefecthq/prefect/pull/23432" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
    <!-- devin-review-badge-end -->

    ---
    Was this helpful? React with 👍 or 👎 to provide feedback.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on Oct 18, 2026 08:42 UTC
    Reviewer

    [!NOTE]

    Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

    Devin Review found 1 new potential issue.

    <!-- devin-review-badge-begin -->
    <a href="https://app.devin.ai/review/prefecthq/prefect/pull/23432" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
    <!-- devin-review-badge-end -->

    ska2704 ska2704 commented on code on Oct 18, 2026 08:44 UTC
    Code Review
    src/prefect/flows.py:1
    @@ -601,11 +605,26 @@ def validate_parameters(self, parameters: dict[str, Any]) -> dict[str, Any]:
             """
     
             def resolve_block_reference(data: Any | dict[str, Any]) -> Any:
    -            if isinstance(data, dict) and "$ref" in data:
    -                from prefect.blocks.core import Block
    +            if not isinstance(data, dict) or "$ref" not in data:
    +                return data
    +
    +            ref = data["$ref"]
    +            if isinstance(ref, str):
    +                if ":" in ref:
    +                    return data

    This is a real compatibility change. The proposed boundary treats direct URI references as schema data and retains UUID URNs for blocks through the explicit block_document_id dictionary. The PR description now calls this out.

    The visitor sees parameter values without field paths or expected Python types, so identical {"$ref": "urn:uuid:..."} inputs cannot mean both schema and block for Any, dictionary, or untyped parameters. Looking up a block and falling back on failure would make schema behavior depend on database contents. Handling only top-level Block annotations would leave nested containers and models inconsistent.

    Could a maintainer confirm this syntax boundary, or whether preserving all implicit UUID spellings is required? The latter needs a broader resolution design. The explicit-ID URN regression passes; this thread remains open for that decision.

    codspeed[bot] codspeed[bot] commented on Oct 18, 2026 08:55 UTC
    Bot

    <!-- __CODSPEED_PERFORMANCE_REPORT_COMMENT__ -->

    Merging this PR will not alter performance

    <details>
    <summary>:warning: <b>5 benchmarks spent significant time in system calls</b></summary>

    System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

    > Measurement and system calls

    > - [` bench_import_module[prefect.flows] ](https://app.codspeed.io/PrefectHQ/prefect/branches/ska2704%3Afix%2Fflow-json-schema-references?uri=benches%2Fbench_import.py%3A%3Abench_import_module%255Bprefect.flows%255D&runnerMode=Simulation&utm_source=github&utm_medium=comment-v2&utm_content=benchmark)

    - [ bench_import_module[prefect.client.schemas.objects] ](https://app.codspeed.io/PrefectHQ/prefect/branches/ska2704%3Afix%2Fflow-json-schema-references?uri=benches%2Fbench_import.py%3A%3Abench_import_module%255Bprefect.client.schemas.objects%255D&runnerMode=Simulation&utm_source=github&utm_medium=comment-v2&utm_content=benchmark)

    - [ bench_import_module[prefect.task_runners] ](https://app.codspeed.io/PrefectHQ/prefect/branches/ska2704%3Afix%2Fflow-json-schema-references?uri=benches%2Fbench_import.py%3A%3Abench_import_module%255Bprefect.task_runners%255D&runnerMode=Simulation&utm_source=github&utm_medium=comment-v2&utm_content=benchmark)

    - [ bench_import_module[prefect.deployments] ](https://app.codspeed.io/PrefectHQ/prefect/branches/ska2704%3Afix%2Fflow-json-schema-references?uri=benches%2Fbench_import.py%3A%3Abench_import_module%255Bprefect.deployments%255D&runnerMode=Simulation&utm_source=github&utm_medium=comment-v2&utm_content=benchmark)

    - [ bench_import_module[prefect.events] ](https://app.codspeed.io/PrefectHQ/prefect/branches/ska2704%3Afix%2Fflow-json-schema-references?uri=benches%2Fbench_import.py%3A%3Abench_import_module%255Bprefect.events%255D&runnerMode=Simulation&utm_source=github&utm_medium=comment-v2&utm_content=benchmark)

    </details>

    ✅ 8 untouched benchmarks
    ⏩ 1` skipped benchmark[^skipped]

    ---

    <sub>Comparing <code>ska2704:fix/flow-json-schema-references</code> (4bb84af) with <code>main</code> (817bc93)</sub>

    <a href="https://app.codspeed.io/PrefectHQ/prefect/branches/ska2704%3Afix%2Fflow-json-schema-references?utm_source=github&utm_medium=comment-v2&utm_content=button">
    <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://codspeed.io/pr-report/open-in-codspeed-dark.svg">
    <source media="(prefers-color-scheme: light)" srcset="https://codspeed.io/pr-report/open-in-codspeed-light.svg">
    <img alt="Open in CodSpeed" src="https://codspeed.io/pr-report/open-in-codspeed-light.svg" width="169" height="32">
    </picture>
    </a>

    [^skipped]: 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

    desertaxle desertaxle commented on code on Oct 19, 2026 15:08 UTC
    Code Review
    src/prefect/flows.py:1
    @@ -601,11 +605,26 @@ def validate_parameters(self, parameters: dict[str, Any]) -> dict[str, Any]:
             """
     
             def resolve_block_reference(data: Any | dict[str, Any]) -> Any:
    -            if isinstance(data, dict) and "$ref" in data:
    -                from prefect.blocks.core import Block
    +            if not isinstance(data, dict) or "$ref" not in data:
    +                return data
    +
    +            ref = data["$ref"]
    +            if isinstance(ref, str):
    +                if ":" in ref:
    +                    return data

    Please preserve the existing direct UUID-URN block references while fixing schema handling. I verified that a saved block passed as {"$ref": block_id.urn} loads on the merge base but fails parameter validation on this head. Add that direct-reference regression alongside the schema-preservation tests; the explicit block_document_id case does not cover existing callers.

    desertaxle desertaxle requested changes on Oct 19, 2026 15:08 UTC
    Changes Requested Reviewer

    Please address the backward-compatibility regression discussed in the inline thread before merging.

    ska2704 ska2704 commented on code on Oct 20, 2026 03:31 UTC
    Code Review
    src/prefect/flows.py:1
    @@ -601,11 +605,26 @@ def validate_parameters(self, parameters: dict[str, Any]) -> dict[str, Any]:
             """
     
             def resolve_block_reference(data: Any | dict[str, Any]) -> Any:
    -            if isinstance(data, dict) and "$ref" in data:
    -                from prefect.blocks.core import Block
    +            if not isinstance(data, dict) or "$ref" not in data:
    +                return data
    +
    +            ref = data["$ref"]
    +            if isinstance(ref, str):
    +                if ":" in ref:
    +                    return data

    Restored direct UUID-URN block references in 4bb84af. The new uuid_urn and uuid_uri cases pass on the merge base, fail on f4fdb44 with missing block fields, and pass after removing the colon guard. The explicit block_document_id URN case remains covered.

    UUID-parseable strings now retain their existing block meaning. I replaced the two conflicting UUID-URI schema expectations with a non-UUID URN case; local paths, relative references, URLs, and schemas inside Pydantic models remain covered. The docstring and PR description state that UUID-shaped schema references keep their legacy block interpretation.

    The flow/block suite passes with 402 passed, 11 existing skips and 2 xfails. All 6 flow typing checks and the applicable commit/push hooks pass.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Oct 20, 2026 03:32 UTC
    Code Review
    src/prefect/flows.py:1
    @@ -601,11 +605,26 @@ def validate_parameters(self, parameters: dict[str, Any]) -> dict[str, Any]:
             """
     
             def resolve_block_reference(data: Any | dict[str, Any]) -> Any:
    -            if isinstance(data, dict) and "$ref" in data:
    -                from prefect.blocks.core import Block
    +            if not isinstance(data, dict) or "$ref" not in data:
    +                return data
    +
    +            ref = data["$ref"]
    +            if isinstance(ref, str):
    +                if ":" in ref:
    +                    return data

    ✅ Resolved: The prior issue was that UUID URN block references were preserved instead of loaded. The current code removes the colon guard, so direct UUID URN block references now resolve; this item is resolved.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Oct 20, 2026 03:32 UTC
    Code Review
    src/prefect/flows.py:1

    <!-- devin-review-comment {"id": "BUG_pr-review-job-05bb9306e9dc44c7abf0d1d146bfbe5d_0001", "file_path": "src/prefect/flows.py", "start_line": 613, "end_line": 614, "side": "LEFT", "based_on_repo_rules": false, "kind": "bug"} -->

    🔴 UUID schema references break flow parameters

    When schema data contains a urn:uuid: or uuid: reference, UUID(ref) treats it as a block ID. Block.load_from_ref then fails for an unsaved UUID or replaces the schema reference with a saved block.

    (Refers to this code)

    <details>
    <summary>Learn more</summary>

    Flow parameters are traversed recursively by visit_collection. The resolver treats strings accepted by Python's UUID parser as saved block IDs. Python also accepts urn:uuid: and uuid: strings, which can be valid URI references inside JSON Schema. Block.load_from_ref raises when a referenced block does not exist, and the flow converts that failure to ParameterTypeError before executing. If the UUID belongs to a saved block, the reference is replaced instead.

    Example: A flow accepting dict[str, Any] receives {"properties": {"item": {"$ref": "urn:uuid:12345678-1234-1234-1234-123456789abc"}}}. Without a saved block at that ID, validation fails instead of passing the schema unchanged.

    Recommended fix: Preserve URI-form $ref strings as schema data, and require an explicit block_document_id dictionary for URI-form block IDs. Restore a regression test for both urn:uuid: and uuid: schema references.

    </details>

    <!-- devin-review-badge-begin -->
    <a href="https://app.devin.ai/review/prefecthq/prefect/pull/23432" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
    <!-- devin-review-badge-end -->

    ---
    Was this helpful? React with 👍 or 👎 to provide feedback.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on Oct 20, 2026 03:32 UTC
    Reviewer

    Devin Review found 1 new potential issue.

    <!-- devin-review-badge-begin -->
    <a href="https://app.devin.ai/review/prefecthq/prefect/pull/23432" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
    <!-- devin-review-badge-end -->

    ska2704 ska2704 commented on code on Oct 20, 2026 03:34 UTC
    Code Review
    src/prefect/flows.py:1

    This is the existing UUID-reference ambiguity documented in the PR body and docstring. The merge base also interprets these strings as block IDs. The maintainer explicitly requested preserving direct UUID-URN block references in https://github.com/PrefectHQ/prefect/pull/23432#discussion_r4315450645, after confirming that the URI guard broke existing callers.

    Requiring an explicit dictionary here would restore that rejected compatibility change. The new direct-reference regressions now pass on both the merge base and this head, while the schema tests cover local paths, relative references, URLs and non-UUID URNs. Distinguishing UUID-shaped schemas from the same block-reference syntax needs a separate design. Resolving this finding against the current backward-compatibility requirement.

    Reviewers
    Assignees
    ska2704 ska2704
    Labels
    risk: low confidence: 84.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.2% (MEDIUM) · Higher = larger blast radius
    47.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 84.9% · Lower = rushed or shallow review
    84.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 7.1% · Safe to merge
    7.1%