Forum Discussion
Using Data Agents for NL to KQL/GQL generation
Hi Team,
I have a graph model and an eventhouse attached to a data agent and only want it to generate the correct KQL/GQL queries based on my natural language question, grounded in the schema object descriptions and example queries I've given for these sources.
Is there a way I can get the data agent to emit just the query but not execute it?
My use-case in NL to Code generation rather than execution and summarization. I tried fine tuning the agent instructions a bit, but I couldn't get the data agent to stop after the nl2code tool call, it ends up also executing the query every time.
Kindly assist if someone has an idea.
PS - I'm aware that Fabric has a real-time intelligence API for NL to KQL generation, but that is insufficient for us because we wanted both GQL and KQL support. Additionally, the RTI API only grounds itself in few-shot examples, unlike the data agent which has an advanced level of grounding using the schema object descriptions, etc. Therefore, I was more curious if this can be done using the data agent itself.
based on the current Fabric data agent architecture, I am not aware of any supported setting that allows the built-in NL2KQL or NL2GQL flow to stop after query generation and return only the generated query.
The dataagent is designed to answer questions against governed data sources. Its natural language tools use the configured schema, object descriptions, instructions, and example queries to generate a query, validate it against the allowed schema, and then execute it to produce a response. Microsoft documenation consistently describes these tools as query generation & execution mechanisms rather than standalone code-generation services.
The configuration options you mentioned, such as schema object descriptions, source instructions, and few shot examples, are effective for improving grounding and influencing how the query is generated. However, they do not currently provide control over the execution stage itself.
One indication of this design is that data Agents generally focus on returning answers rather than exposing generated query text as a 1st class output. Even in some integration scenarios, the generated SQL/KQL is not exposed directly, which suggests the product is currently optimised for conversational analytics rather than NL-to-code workflows.
For a use case where the generated KQL/GQL must be reviewed, modified, approved, or executed by another system, I would not rely on data agent instructions to suppress execution. As currently implemented the exec step appears to be part of the agent's intended end2end workflow.
So for your specific question, I do not believe there is currently a supported "generate-only" or "do-not-execute" mode for fabric data agents. The grounding capabilities can influence query generation quality, but they cannot reliably prevent the generated query from being executed.
Help make this community better for everyone: if this answer resolved your issue, please accept it or leave an kudos. If not, share more details in a comment so we can continue the discussion and find the right solution.
3 Replies
- Vinodh247
Super User
based on the current Fabric data agent architecture, I am not aware of any supported setting that allows the built-in NL2KQL or NL2GQL flow to stop after query generation and return only the generated query.
The dataagent is designed to answer questions against governed data sources. Its natural language tools use the configured schema, object descriptions, instructions, and example queries to generate a query, validate it against the allowed schema, and then execute it to produce a response. Microsoft documenation consistently describes these tools as query generation & execution mechanisms rather than standalone code-generation services.
The configuration options you mentioned, such as schema object descriptions, source instructions, and few shot examples, are effective for improving grounding and influencing how the query is generated. However, they do not currently provide control over the execution stage itself.
One indication of this design is that data Agents generally focus on returning answers rather than exposing generated query text as a 1st class output. Even in some integration scenarios, the generated SQL/KQL is not exposed directly, which suggests the product is currently optimised for conversational analytics rather than NL-to-code workflows.
For a use case where the generated KQL/GQL must be reviewed, modified, approved, or executed by another system, I would not rely on data agent instructions to suppress execution. As currently implemented the exec step appears to be part of the agent's intended end2end workflow.
So for your specific question, I do not believe there is currently a supported "generate-only" or "do-not-execute" mode for fabric data agents. The grounding capabilities can influence query generation quality, but they cannot reliably prevent the generated query from being executed.
Help make this community better for everyone: if this answer resolved your issue, please accept it or leave an kudos. If not, share more details in a comment so we can continue the discussion and find the right solution.
- FarhanJeelani
Super User
Hi hathalye,
As far as I know, this isn't possible today. The data agent's tool flow is fixed. The NL2KQL (and graph) tool generates the query, validates it, and then the agent runs it and summarizes the result. There's no setting or instruction that stops it after generation, which is why tuning the instructions didn't work.
The closest workaround is to call the agent through its API or the Fabric Data Agent SDK instead of the chat UI. Then read the run steps (the tool-call details) for each question. The generated KQL/GQL is in there, so you can take the query and ignore the executed answer. The query still runs in the background, so you'll use some capacity and need read access to the data. But you keep the full grounding from your schema descriptions and example queries, which is the part you care about.
If the extra execution is a problem, it's worth raising on Fabric Ideas as a "generate only / dry run" mode. It's a reasonable ask for NL-to-code scenarios like yours.
Sources:
- Fabric data agent concepts – Microsoft Learn
- Create a Fabric data agent – Microsoft Learn
Please mark this post as solution if it helps you. Appreciate Kudos.
- hathalyeNew Member
Thanks FarhanJeelani and Vinodh247, really solid answers.
Similar to what Farhan suggested, picking the query up from the run steps is what we also eventually ended up doing. However, this is a little hacky and involves messy parsing logic which is fragile.
Doesn't seem too difficult for this to be supported natively though. I've floated an idea here - NL to KQL/GQL generation | Microsoft Fabric Community.