Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sql Agent Laravel Package

knobik/sql-agent

Self-learning text-to-SQL agent for Laravel that turns natural language into accurate SQL using knowledge bases, memory, and live schema context. Includes SQL safety guardrails and a built-in chat UI.

View on GitHub
Deep Wiki
Context7

SQL Agent for Laravel is a self-learning text-to-SQL agent that converts natural language questions into accurate SQL using context, memory, and a built-in chat UI. It grounds each query with six context layers—table schemas, business annotations, proven query patterns, accumulated learnings, live schema introspection, and conversation history—so the LLM reliably understands your data.

  • Knowledge Base — curated table metadata, business rules, and working SQL patterns
  • Self-Learning — saves fixes from failed queries so the agent improves over time
  • SQL Safety — configurable guardrails block destructive operations
  • Multi-Provider — works with OpenAI, Anthropic, Ollama, Gemini, Mistral, xAI, and more
$response = SqlAgent::run('Who are our top 5 customers by spending?');
$response->answer; // "Here are the top 5 customers..."
$response->sql;    // "SELECT c.name, SUM(o.total_amount)..."
Frequently asked questions about Sql Agent
How do I install and configure knobik/sql-agent in a Laravel app?
Install it with composer require knobik/sql-agent, then run php artisan sql-agent:install to publish configuration and assets. Add your LLM provider and model to .env using SQL_AGENT_LLM_PROVIDER and SQL_AGENT_LLM_MODEL, such as openai and gpt-4o. The package is in beta, so review the published config and test in a staging environment before production rollout.
Which LLM providers can I use with SQL Agent for Laravel?
SQL Agent supports multiple LLM providers including OpenAI, Anthropic, Ollama, Gemini, Mistral, and xAI. You select the provider and model through environment variables like SQL_AGENT_LLM_PROVIDER and SQL_AGENT_LLM_MODEL. This lets you trade off cost, latency, and accuracy, for example using Ollama for local or offline use or OpenAI for production-grade results.
Is knobik/sql-agent compatible with Laravel 10 and Laravel 11?
The package has been tested with Laravel 10 and 11 according to its technical evaluation, but you should confirm the exact constraints in its composer.json before installing. It is Laravel-native and works with Eloquent and the Query Builder, reducing abstraction overhead. Because it is still in beta, verify compatibility in your specific application version and test thoroughly.
How does the self-learning feature in SQL Agent work?
When a generated query fails, the agent diagnoses the error, attempts a fix, and saves that learning for future use. These accumulated learnings become part of the context layers used on subsequent natural language queries. Successful results can also optionally be saved as knowledge, improving accuracy over time if user corrections are reliable.
What SQL safety guardrails does knobik/sql-agent provide?
SQL Agent includes configurable SQL safety guardrails designed to prevent destructive operations such as unintended writes or drops. Query validation is a critical part of the package, but the technical evaluation notes these features are not yet proven in production because the package is in beta. You should review and tighten the configuration for your database and test destructive-operation blocking explicitly.
Can I use the built-in chat UI or expose SQL Agent as an API?
Yes, SQL Agent ships with a built-in chat UI that reduces frontend development effort and is suitable for quick deployment. Alternatively, you can expose it as an API endpoint such as /api/sql-agent and build a custom React or Vue interface. Customizing the built-in UI may require Blade, Livewire, or Inertia integration depending on your stack.
How do I control LLM costs and latency when using SQL Agent in production?
High-volume usage can escalate LLM expenses, especially with models like GPT-4o, so cache frequent responses and use cheaper models for low-complexity queries. For latency-sensitive use cases, consider async processing or local caching to avoid blocking real-time requests. Also set budgets, alerts, and rate-limit handling to protect against API outages or throttling.
How does SQL Agent ground natural language queries with schema and knowledge base context?
The agent uses six context layers: table usage with schema, columns, and relationships; human annotations with metrics and business rules; query patterns of known-good SQL; learnings from errors; runtime schema introspection; and conversation history. These layers come from curated JSON and SQL files under knowledge directories plus on-demand tools like save_learning. This multi-layer grounding is designed to reduce hallucination and improve SQL accuracy for complex business logic.
What are the main production risks of using knobik/sql-agent?
Key risks include beta-stage API instability, dependence on external LLM APIs for latency, cost, and rate limits, and reliance on accurate user feedback for the self-learning loop. Schema drift can also break context when tables or columns change, and SQL safety features are not yet production-proven. Mitigate by piloting in staging, monitoring accuracy and LLM latency, automating schema sync, and keeping a manual SQL override fallback.
How should I test SQL Agent for ambiguous questions and malformed SQL?
Start with a staging pilot using a subset of tables and non-critical reporting or analytics queries. Validate edge cases such as ambiguous natural language, complex joins, subqueries, and malformed SQL, and log user corrections to a feedback table for review. Track query accuracy and LLM latency, and phase out legacy SQL only where the agent succeeds consistently, for example above 90 percent.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
adachsoft/php-code-style