Skip to content

feat(datafabric): add fetch_ontology tool to DF inner SQL agent#911

Open
sankalp-uipath wants to merge 2 commits into
mainfrom
feat/datafabric-ontology-fetch-tool
Open

feat(datafabric): add fetch_ontology tool to DF inner SQL agent#911
sankalp-uipath wants to merge 2 commits into
mainfrom
feat/datafabric-ontology-fetch-tool

Conversation

@sankalp-uipath

Copy link
Copy Markdown

What

Adds an inner-level fetch_ontology tool alongside execute_sql in the Data Fabric tool's SQL sub-agent. When enabled, the inner LLM can fetch a configured ontology's OWL from the QueryEngine ontology REST API and use it to write semantically-correct SQL (exact class/property names, value formats, join keys).

Why

The inner SQL agent gets columns/types but not their meaning — it guesses value formats ('in_transit' vs 'In Transit'), boolean shapes (= true vs = 1), and joins. The ontology supplies these, so SQL is correct on the first attempt instead of failing and retrying.

How

  • ontology_client.pyGET datafabric_/api/ontologies/{name}/files/owl via the authenticated EntitiesService (reuses auth + tenant/account scoping). Name regex-validated, 1 MB cap, notation-agnostic (Turtle or OWL Functional Notation) via the JSON wrapper.
  • ontology_fetch_tool.pyfetch_ontology leaf tool + cached fetcher; fenced/labelled output; graceful degradation on failure.
  • datafabric_subgraph.py — binds the tool when configured; dispatches inner tool calls by name (only a successful execute_sql is terminal, so fetch_ontology loops back to the inner LLM).
  • datafabric_tool.py — threads ontology_name/folder_key from agent_config or env (UIPATH_ONTOLOGY_NAME / UIPATH_FOLDER_KEY).

Notes

  • Opt-in & backward compatible: no ontology name configured → tool not added, behaviour unchanged.
  • Preliminary — raising early for review; not yet verified against a live tenant.
  • ruff + py_compile clean.

Open items

  • Confirm folder scoping at runtime (QE requires a folder).
  • Confirm the ecommerce ontology exists in the QueryEngine store.
  • Confirm the inner LLM reliably chooses to call fetch_ontology.

Copilot AI review requested due to automatic review settings June 16, 2026 12:50
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
36.7% Coverage on New Code (required ≥ 90%)

See analysis details on SonarQube Cloud

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an optional fetch_ontology inner tool to the Data Fabric SQL sub-agent so the inner LLM can retrieve a configured ontology’s OWL schema from the QueryEngine REST API and use it to generate semantically-correct SQL.

Changes:

  • Introduces an ontology REST client (fetch_ontology_owl) with name validation and size limiting.
  • Adds a fetch_ontology leaf tool with an instance-level cache and wires it into the inner Data Fabric subgraph alongside execute_sql.
  • Threads ontology_name / folder_key into the Data Fabric tool construction path (with an env-var fallback).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/uipath_langchain/agent/tools/datafabric_tool/ontology_fetch_tool.py New leaf tool (fetch_ontology) and cached fetcher wrapper for inner SQL agent use.
src/uipath_langchain/agent/tools/datafabric_tool/ontology_client.py New client helper to fetch OWL content via EntitiesService.request_async, including name validation and payload cap.
src/uipath_langchain/agent/tools/datafabric_tool/models.py Adds an intentionally-empty args schema (OntologyFetchInput) for the new tool.
src/uipath_langchain/agent/tools/datafabric_tool/datafabric_tool.py Plumbs ontology_name / folder_key into the query handler creation (currently with env-var fallback).
src/uipath_langchain/agent/tools/datafabric_tool/datafabric_subgraph.py Adds optional fetch_ontology tool binding and dispatch-by-tool-name inside the inner subgraph.

Comment on lines +159 to +163
Dispatches by tool name so the sub-graph can host more than one tool
(e.g. ``execute_sql`` and ``fetch_ontology``). Only a successful
``execute_sql`` that returned rows is terminal; every other tool
(including ontology fetch) reports ``False`` so the router loops back to
the inner LLM, letting it use the result to write or refine SQL.
Comment on lines +171 to +175
# Ontology name is pinned from configuration (not chosen by the LLM).
# Falls back to env vars for local/demo runs that have no Agent Builder UI.
# When unset, no fetch_ontology tool is added (fully backward compatible).
ontology_name = config.get(ONTOLOGY_NAME) or os.getenv("UIPATH_ONTOLOGY_NAME")
folder_key = config.get(FOLDER_KEY) or os.getenv("UIPATH_FOLDER_KEY")
Comment on lines +31 to +33
# Defensive cap so a malformed or oversized file can never blow up the prompt
# or token budget. Real OWL 2 QL files are a few KB; QueryEngine caps at 10 MB.
_MAX_OWL_BYTES = 1_000_000
Comment on lines +47 to +50
The result is cached on this instance. Because the instance lives as long
as the compiled sub-graph (which the handler caches), repeated calls across
queries hit the API at most once, surviving the per-query reset of the
inner sub-graph state.
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.

2 participants