Troubleshooting
No Knowledge Found or Poor Results
Section titled “No Knowledge Found or Poor Results”If the agent isn’t finding relevant context or producing poor SQL:
- Verify your knowledge files are valid JSON and follow the expected format.
- Reimport your knowledge with
php artisan sql-agent:load-knowledge --recreate. - Check that the
sql_agent_table_metadatatable has entries:SELECT COUNT(*) FROM sql_agent_table_metadata. - Add more descriptive column information — the richer your descriptions, the better the agent performs.
Maximum Iterations Reached
Section titled “Maximum Iterations Reached”The agent couldn’t complete the task within the allowed number of tool-calling rounds:
- Increase the limit by setting
SQL_AGENT_MAX_ITERATIONSin your.envfile. - Add more specific knowledge about the tables involved so the agent needs fewer introspection steps.
- Simplify the question or break it into smaller, more focused queries.
SQL Errors in Production
Section titled “SQL Errors in Production”If queries are being rejected or failing:
- Check that
sql-agent.sql.allowed_statementsincludes the statement types your queries need (default:SELECTandWITH). - Verify the query doesn’t use any of the
sql-agent.sql.forbidden_keywords. - Review
sql-agent.sql.max_rowsif result truncation is causing issues.
Slow Response Times
Section titled “Slow Response Times”If the agent is taking too long to respond:
- Use a faster model (e.g.,
gpt-4o-miniinstead ofgpt-4o). - Reduce
chat_history_lengthto minimize the context sent to the LLM. - Consider the
databasesearch driver for simpler setups — it avoids external service round-trips.
LLM API Errors
Section titled “LLM API Errors”If you’re getting authentication or connection errors from the LLM provider:
- Verify your API key is correct and has not expired.
- Check your API quota and rate limits with your provider.
- For Ollama, ensure the service is running (
ollama serve) and the model has been pulled (ollama pull <model>).
Search Not Finding Relevant Knowledge
Section titled “Search Not Finding Relevant Knowledge”If the search driver isn’t returning expected results:
- Ensure migrations ran successfully — full-text indexes are created in the migrations.
- For MySQL, verify the tables use InnoDB or MyISAM engine (both support full-text indexes).
- For SQL Server, ensure a full-text catalog is configured.
- Consider switching to the
pgvectorsearch driver for semantic similarity search.
pgvector Driver Errors
Section titled “pgvector Driver Errors”If you see errors about missing classes like Pgvector\Laravel\Vector or Pgvector\Laravel\HasNeighbors:
- Install the required package:
composer require pgvector/pgvector. - Run
php artisan sql-agent:setup-pgvectorto publish migrations and create the embeddings table. - Verify your
SQL_AGENT_EMBEDDINGS_CONNECTIONpoints to a PostgreSQL database with the pgvector extension installed.