When use SQL Tool, agent gives ValidationError

Python Code:

from sqlalchemy import create_engine
from agno.agent import Agent
from agno.tools.sql import SQLTools

user = “user”
password = “password”
host = “host”
port = 1234
schema = “schema”
dialect = “mysql”

db_url = f"mysql+pymysql://{user}:{password}@{host}:{port}/{schema}"
db_engine = create_engine(db_url)

sql_tools = SQLTools(
user=user,
password=password,
host=host,
port=port,
schema=schema,
dialect=dialect,
db_engine=db_engine )

agent = Agent(
model=Ollama(id=“qwen2.5:3b-instruct”),
tools=[sql_tools]
)

agent.print_response(
“List the tables in the database. Tell me about contents of one of the tables”,
markdown=True,
)

Error:
Traceback (most recent call last):
File “/home/mohkaab/PycharmProjects/CareVision/care_vision_siri/working.py”, line 469, in
agent.print_response(
File “/home/mohkaab/PycharmProjects/PythonProject/.venv/lib/python3.12/site-packages/agno/agent/agent.py”, line 3511, in print_response
run_response = self.run(
^^^^^^^^^
File “/home/mohkaab/PycharmProjects/PythonProject/.venv/lib/python3.12/site-packages/agno/agent/agent.py”, line 870, in run
return next(resp)
^^^^^^^^^^
File “/home/mohkaab/PycharmProjects/PythonProject/.venv/lib/python3.12/site-packages/agno/agent/agent.py”, line 592, in _run
model_response = self.model.response(messages=run_messages.messages)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/mohkaab/PycharmProjects/PythonProject/.venv/lib/python3.12/site-packages/agno/models/base.py”, line 163, in response
assistant_message, has_tool_calls = self._process_model_response(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/mohkaab/PycharmProjects/PythonProject/.venv/lib/python3.12/site-packages/agno/models/base.py”, line 287, in _process_model_response
response = self.invoke(messages=messages)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/mohkaab/PycharmProjects/PythonProject/.venv/lib/python3.12/site-packages/agno/models/ollama/chat.py”, line 203, in invoke
return self.get_client().chat(
^^^^^^^^^^^^^^^^^^^^^^^
File “/home/mohkaab/PycharmProjects/PythonProject/.venv/lib/python3.12/site-packages/ollama/_client.py”, line 340, in chat
tools=[tool for tool in _copy_tools(tools)],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/mohkaab/PycharmProjects/PythonProject/.venv/lib/python3.12/site-packages/ollama/_client.py”, line 1142, in _copy_tools
yield convert_function_to_tool(unprocessed_tool) if callable(unprocessed_tool) else Tool.model_validate(unprocessed_tool)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/mohkaab/PycharmProjects/PythonProject/.venv/lib/python3.12/site-packages/pydantic/main.py”, line 627, in model_validate
return cls.pydantic_validator.validate_python(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for Tool
function.parameters.properties.limit.type
Input should be a valid string [type=string_type, input_value=[‘number’, ‘null’], input_type=list]
For further information visit Redirecting...

Hi @muhammad.haris
Thanks for reaching out and for using Agno! I’ve looped in the right engineers to help with your question. We usually respond within 48 hours, but if this is urgent, just let us know, and we’ll do our best to prioritize it.
Appreciate your patience—we’ll get back to you soon! :smile:

Hey @muhammad.haris! I ran this code that worked for me

from agno.agent import Agent
from agno.tools.sql import SQLTools

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

agent = Agent(tools=[SQLTools(db_url=db_url)])
agent.print_response(
    "List the tables in the database. Tell me about contents of one of the tables",
    markdown=True,
)

I see that you have the db_url that you can pass directly the SQLTools and it should work. Let me know if you are able to make it run!

i have updated the code as you suggested but same validation errors occurs. DB is connected but error occurs after when agent.print_response function is called.

updated code:

from agno.agent import Agent
from agno.tools.sql import SQLTools

db_url = f"mysql+pymysql://{user}:{password}@{host}:{port}/{schema}"

agent = Agent(model=Ollama(id=“qwen2.5:3b-instruct”),tools=[SQLTools(db_url=db_url)])
agent.print_response(
“List the tables in the database. Tell me about contents of one of the tables”,
markdown=True,
)

@Monali @manthanguptaa

Apologies for the delay in response @muhammad.haris
Getting engineers on this asap

Hey @muhammad.haris! I tried your code, and I was able to get the desired results.

from agno.agent import Agent
from agno.models.ollama import Ollama
from agno.tools.sql import SQLTools

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

agent = Agent(model=Ollama(id="qwen2.5:3b-instruct"), tools=[SQLTools(db_url=db_url)], show_tool_calls=True)
agent.print_response(
    "List the tables in the database. Tell me about contents of one of the tables",
    markdown=True,
)

Though you are using a 3b model which isn’t powerful enough to make multiple tool calls at once. It will hallucinate in making a single tool call. I had suggest to give it queries that invoke a single tool call or go for a stronger model like llama3.3