Skip to content

feat(datafabric): standalone ontology tool grounded on OWL + R2RML#911

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

feat(datafabric): standalone ontology tool grounded on OWL + R2RML#911
sankalp-uipath wants to merge 42 commits into
mainfrom
feat/datafabric-ontology-fetch-tool

Conversation

@sankalp-uipath

@sankalp-uipath sankalp-uipath commented Jun 16, 2026

Copy link
Copy Markdown

What

Adds a standalone Data Fabric ontology tool for low-code agents. The agent selects ontologies (not entities); the tool derives the entities it may query from the ontology's R2RML, resolves their schemas, and runs the existing inner SQL sub-graph grounded on both the OWL (semantic schema) and the R2RML (ontology→table/column mapping).

An ontology context (contextType: "datafabricontology") now becomes a tool on its own — no entitySet required in agent.json.

How it works (first invocation, cached)

  1. Fetch the ontology's R2RML (critical — it is the entity allow-list) and OWL (grounds the prompt) via EntitiesService.get_ontology_file_async.
  2. Parse R2RML with rdflib → the closed (entity_name, folder_path) allow-list, reading one rr:tableName (via rr:logicalTable) + one uipath:folderPath per rr:TriplesMap.
  3. Resolve the allow-list concurrently (asyncio.gather): distinct folderPath → folder_key (folders.retrieve_key_async), then name → id (entities.retrieve_by_name_async), and delegate to the SDK's public entities.resolve_entity_set_async to fetch the schemas and build the folder-scoped EntitiesService (routing each entity's queries to its folder). Using the public resolver means the tool builds nothing from SDK internals.
  4. Build a dedicated ontology system prompt (OWL + R2RML + entity schemas) and compile the ontology DataFabricGraph — the inner agent still has a single tool, execute_sql.

Everything from the sub-graph down (execute_sqlquery_entity_records_async) mirrors the entity tool.

Layout — the entity tool is left untouched

All ontology code lives in its own datafabric_tool/ontology/ subpackage. The entity tool's files are byte-identical to main: datafabric_tool.py, datafabric_subgraph.py, datafabric_prompt_builder.py, and the package __init__.py are unchanged by this PR. context_tool.py is the only shared file touched — it builds the standalone ontology tool for the ontology context (flag-gated) and imports the tool directly from datafabric_tool.ontology.

New — datafabric_tool/ontology/

  • ontology_r2rml.pyrdflib-based parser: parse_r2rml_entities() → the (entity_name, folder_path) allow-list (parses Turtle as an RDF graph; R2RMLParseError on invalid Turtle or contract violations).
  • ontology_tool.pyresolve_ontology_entities() (the concurrent resolver), DataFabricOntologyQueryHandler, create_datafabric_ontology_tool(); owns the DATAFABRIC_ONTOLOGY_FF flag constant.
  • ontology_subgraph.py — a self-contained, prompt-agnostic duplicate of DataFabricGraph (takes a pre-built system_prompt), so the entity sub-graph stays identical to main.
  • ontology_prompt_builder.py — the ontology tool's inner prompt (OWL + R2RML + entity schemas), self-contained.
  • ontology_fetcher.pyfetch_ontology_file (raw content + media type; raises) + fence_ontology_block.

Design decisions

  • Closed allow-list (Option A): the entities the tool can touch are exactly those declared in the ontology's R2RML — the LLM can never widen scope. execute_sql's blast radius = the resolved set.
  • uipath:folderPath (a folder path, not a GUID): R2RML has no folder concept and is deployment-agnostic; rr:tableName stays a valid SQL table name. Folder identity is resolved through the trusted folder service, never from mapping content. (Authoring contract documented for the ontology-authoring skill.)
  • rdflib parser: the R2RML is parsed as an RDF graph rather than scanned with regexes, so authoring variations (predicate order, whitespace, compact one-line maps, prefix/@base differences) are handled by a real Turtle parser. Validated against the live california-schools mapping fetched from Data Fabric.
  • Duplicated, isolated sub-graph: ontology_subgraph.py is an intentional copy of datafabric_subgraph.py so the entity path is not modified. It is excluded from Sonar copy-paste detection (sonar.cpd.exclusions) rather than sharing code, to preserve that isolation.
  • No SDK change for the core feature — all new code is in uipath-langchain-python over existing public uipath-platform methods.

Feature flag

  • Gated by DataFabricOntologyEnabled (default off), a single shared constant owned by the ontology subpackage.
  • Two guards (defense in depth): the tool-factory entry (context_tool — off ⇒ no tool created, feature fully inert) and the handler's lazy init (re-checks before any OWL/R2RML fetch/parse/resolve). Off ⇒ the agent runs exactly as before; the entity tool is flag-independent.

Security

  • Entity/folder scope is bounded by the R2RML allow-list; folder keys come only from trusted folder-path resolution (not the LLM).
  • execute_sql's single-statement sqlparse guard is unchanged.
  • OWL/R2RML are injected as prompt context; a hostile ontology can only reference entities it itself declares (Option A), which still pass folder-scoped resolution.

Testing

  • Unit tests for the parser (incl. the live california-schools shape), resolver (concurrent folder-key + by-name id fetch, delegation to resolve_entity_set_async), the ontology prompt builder, the ontology sub-graph nodes, the factory, and the flag guard. New ontology modules are covered ≥99%.
  • Live e2e on alpha (datafabric/ab, gpt-5.4, california-schools ontology): flag prefetched on → R2RML + OWL fetched → folderPath resolved → 3 entities resolved by name → OWL+R2RML-grounded SQL (join on the R2RML FK) executed folder-scoped → correct answer. Confirmed retrieve_by_name (/metadata) returns populated field schemas.

Notes / dependencies

  • Depends on SDK #1728 (merged), which ships the ontology binding: ontologySet on the context, AgentContextType.DATA_FABRIC_ONTOLOGY, get_ontology_file_async, and resolve_entity_set_async. The feature needs uipath>=2.13.2 / uipath-platform>=0.2.1; pyproject.toml currently pins the higher uipath>=2.13.5 / uipath-platform>=0.2.4 adopted from main. No env-based configuration fallback is used — ontologies come only from the context's ontologySet.
  • Adds rdflib>=7.0.0, <8.0.0 for the R2RML parser.
  • Runtime flag delivery also requires DataFabricOntologyEnabled in uipath-agents-python's _ALL_FLAGS prefetch + the gitops flag deployed for the target tenants (both already in place from the prior work).
  • Authoring dependency: ontologies must be published with a uipath:folderPath per rr:TriplesMap (authoring-skill guidelines provided) — otherwise resolution fails loudly by design.
  • Supersedes the earlier "inject ontology into the entity tool" approach and folds in the R2RML grounding work.

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

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 thread src/uipath_langchain/agent/tools/datafabric_tool/datafabric_subgraph.py Outdated
Comment thread src/uipath_langchain/agent/tools/datafabric_tool/datafabric_tool.py Outdated
Comment thread src/uipath_langchain/agent/tools/datafabric_tool/ontology_client.py Outdated
Comment thread src/uipath_langchain/agent/tools/datafabric_tool/ontology_fetch_tool.py Outdated
Comment thread src/uipath_langchain/agent/tools/datafabric_tool/ontology_client.py Outdated

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

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

Comment thread src/uipath_langchain/agent/tools/datafabric_tool/datafabric_subgraph.py Outdated
Comment thread src/uipath_langchain/agent/tools/datafabric_tool/datafabric_tool.py Outdated
Comment thread tests/agent/tools/test_datafabric_ontology_subgraph.py Outdated

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

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

Comment thread src/uipath_langchain/agent/tools/datafabric_tool/ontology_fetch_tool.py Outdated
Comment thread src/uipath_langchain/agent/tools/datafabric_tool/ontology_fetch_tool.py Outdated
Comment thread src/uipath_langchain/agent/tools/datafabric_tool/datafabric_tool.py Outdated

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Comment thread src/uipath_langchain/agent/tools/datafabric_tool/datafabric_subgraph.py Outdated
Comment thread src/uipath_langchain/agent/tools/datafabric_tool/ontology_fetch_tool.py Outdated
Comment thread src/uipath_langchain/agent/tools/datafabric_tool/ontology_fetch_tool.py Outdated
Comment thread tests/agent/tools/test_datafabric_tool_ontology_factory.py Outdated
Comment thread tests/agent/tools/test_datafabric_tool_ontology_factory.py Outdated
Comment thread tests/agent/tools/test_datafabric_tool_ontology_factory.py Outdated

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

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Comment thread src/uipath_langchain/agent/tools/datafabric_tool/ontology_fetcher.py Outdated
Comment thread pyproject.toml Outdated
sankalp-uipath and others added 4 commits July 3, 2026 12:57
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ogy-fetch-tool

# Conflicts:
#	pyproject.toml
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sankalp-uipath sankalp-uipath force-pushed the feat/datafabric-ontology-fetch-tool branch from 44905ac to 69d884c Compare July 7, 2026 08:44
sankalp-uipath and others added 2 commits July 7, 2026 14:14
…-builder sections

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…flib R2RML parser

- revert datafabric_subgraph.py / datafabric_tool.py to main (no pollution)
- move ontology files under datafabric_tool/ontology/ with duplicated prompt-agnostic subgraph
- replace regex R2RML parser with rdflib; add rdflib dep
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

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

Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.

Comment thread src/uipath_langchain/agent/tools/datafabric_tool/ontology/ontology_tool.py Outdated
Comment thread src/uipath_langchain/agent/tools/datafabric_tool/ontology/ontology_tool.py Outdated
Comment thread pyproject.toml Outdated
sankalp-uipath and others added 5 commits July 7, 2026 18:16
…P/CPD false positives

- resolve_ontology_entities: gather folder-key + schema fetches concurrently
- suppress S5332 on RDF namespace IRIs (identifiers, not endpoints)
- exclude intentionally-duplicated ontology subpackage from Sonar CPD
- clarify entity-name->folder routing model
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ogy-fetch-tool

# Conflicts:
#	pyproject.toml
#	uv.lock
…tity_set_async

Resolve name->id then delegate to the SDK's public entity-set resolver to build
the folder-scoped service, removing reliance on SDK-private config/execution_context.

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

Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.

Comment thread tests/agent/tools/test_ontology_fetcher.py Outdated
…docstring path

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

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.

6 participants