Skip to content

fix(agent): return message instead of raising ItemNotFoundError in get_lineage_paths_between#17014

Open
psaikaushik wants to merge 2 commits intodatahub-project:masterfrom
psaikaushik:fix/16882-graceful-lineage-not-found
Open

fix(agent): return message instead of raising ItemNotFoundError in get_lineage_paths_between#17014
psaikaushik wants to merge 2 commits intodatahub-project:masterfrom
psaikaushik:fix/16882-graceful-lineage-not-found

Conversation

@psaikaushik
Copy link
Copy Markdown

Summary

When no lineage path exists between two assets, get_lineage_paths_between raises ItemNotFoundError. In an agent/ADK context this surfaces as an unhandled exception instead of a useful response.

Closes #16882

What Changed

datahub-agent-context/src/datahub_agent_context/mcp_tools/lineage.py

  • get_lineage_paths_between() now catches ItemNotFoundError and returns a friendly message dict instead of raising
  • Added _build_no_path_found_message() helper that returns a consistent response with message, source, target, pathCount=0, and empty paths
  • Both code paths are covered: auto-discover (tries downstream then upstream) and explicit direction
  • Updated docstring to document the new return shape for the no-path case
  • Removed ItemNotFoundError from the Raises section of the docstring

datahub-agent-context/tests/unit/mcp_tools/test_lineage.py

  • Replaced test_path_not_found_raises_error (which expected ItemNotFoundError) with test_path_not_found_returns_message that checks the message dict
  • Added test_path_not_found_auto_discover_returns_message for the auto-discover code path

Before vs After

Before (raises, agent sees unhandled error):

ItemNotFoundError: No lineage path found between urn:li:dataset:A and urn:li:dataset:B
in either upstream or downstream direction

After (returns dict, agent gets a usable response):

{
  "message": "No lineage path found between urn:li:dataset:A and urn:li:dataset:B in either upstream or downstream direction.",
  "source": {"urn": "urn:li:dataset:A"},
  "target": {"urn": "urn:li:dataset:B"},
  "pathCount": 0,
  "paths": []
}

Notes

  • Internal helpers (_find_upstream_lineage_path, _find_lineage_path) still raise ItemNotFoundError for control flow. Only the public-facing get_lineage_paths_between catches and converts them.
  • No changes to get_lineage() which has different behavior and is not affected by this issue.

…ge_paths_between

When no lineage path exists between two assets, get_lineage_paths_between
was raising ItemNotFoundError. In an agent/ADK context this surfaces as
an unhandled exception instead of a useful response.

Now it returns a dict with a human-readable message, the source/target
info, pathCount=0, and an empty paths array. This lets agents handle
"no lineage found" as a normal outcome rather than an error.

Also adds _build_no_path_found_message() helper for consistent formatting
across both auto-discover and explicit direction code paths.

Tests updated: test_path_not_found_raises_error replaced with
test_path_not_found_returns_message that checks the message dict.
Added test_path_not_found_auto_discover_returns_message for the
auto-discover path.

Closes datahub-project#16882
The import was left over after replacing test_path_not_found_raises_error
(which used pytest.raises(ItemNotFoundError)) with
test_path_not_found_returns_message (which checks the message dict).
Ruff flags this as F401 (unused import).
@maggiehays maggiehays added the needs-review Label for PRs that need review from a maintainer. label Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution PR or Issue raised by member(s) of DataHub Community needs-review Label for PRs that need review from a maintainer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_lineage_between return the ItemNotFoundError, Should be a message instead of error from adk module

2 participants