One of the recurring challenges when building AI agents is giving the LLM a safe, accurate view of your database — and then letting it query that database without exposing raw credentials or risking runaway queries. AgentQL is a reusable .NET library I built to solve exactly that. It sits between your EF Core DbContext and any AI provider, handling both schema description and query execution so you don’t have to wire it up yourself.
The library works in three steps. First, it introspects your EF Core model — tables, columns, types, relationships, enums, and inheritance hierarchies — and produces a plain-text schema description the LLM can actually reason about. Second, it exposes three tool functions (GetDatabaseSchema, ExecuteQuery, and ReportFailure) through Microsoft.Extensions.AI, so any compatible chat client can call them automatically via function calling. Third, it executes the resulting SQL queries safely inside transactions with configurable row limits, timeouts, and optional read-only enforcement.
Getting started is minimal. A single call to AddAgentQLChat<MyDbContext>() in your DI setup registers everything — the schema provider, the query executor, the plugin, and the chat client — and you can point it at OpenAI, Anthropic, or a local Ollama model by changing one option. For cases where you only need schema introspection and query execution without a bundled chat client, a lighter AddAgentQL<T>() extension is available that just registers ISchemaProvider and IQueryExecutor.
Fine-grained control over what the LLM can see is built in from the start. You can annotate entity classes and properties with [AgentQLEntity], [AgentQLProperty], and [AgentQLIgnore] attributes, or configure inclusion and exclusion entirely through a fluent API — useful for keeping sensitive fields like password hashes or SSNs out of the schema description without modifying your domain model. The library is available on NuGet.
The repo includes a Blazor demo app that simulates a travel agency chat interface backed by a self-seeding SQLite database — a good way to see everything working end to end before wiring it into your own project. The project is open source under the MIT licence. If you find it useful, a ⭐ star on the repo would mean a lot, and feel free to drop a comment below if you have questions or ideas.