# NL2SQLTool returning only validation errors

**URL:** <https://community.crewai.com/t/nl2sqltool-returning-only-validation-errors/7031>\
**Category:** CrewAI Community Support\
**Tags:** tools\_issues\
**Created:** [September 11, 2025, 11:44pm UTC](https://community.crewai.com/t/nl2sqltool-returning-only-validation-errors/7031 "2025-09-11T23:44:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![user1024](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/user1024/32/4018_2.png) [@user1024](https://community.crewai.com/u/user1024)\
**Post date:** [September 11, 2025, 11:44pm UTC](https://community.crewai.com/t/nl2sqltool-returning-only-validation-errors/7031/1 "2025-09-11T23:44:41Z")

</div>

# Situation

I’ve been trying to get NL2SQLTool to work and have not had any luck, so I tried a very simple setup and am still stuck with a validation error. Hoping someone can help as I have not been able to find a working NL2SQLTool example.

## This is my simplified agents.yaml -

```auto
data_engineer:
  role: >
    {topic} SQL Data Engineer
  goal: >
    Fetch employee data from MySQL.
    Using data in a mysql database in table {table_name},
    put together a list of employees' last names.
  backstory: >
    You are experienced with querying mysql tables.

```

## And my simplified tasks.yaml -

```auto
query_task:
  description: >
    Query employees from a mysql database.
    To accomplish this retrieve the {topic} data from the {table_name} table
    and show a list of last names.
  expected_output: >
    The {topic} employee data will be output in markdown format.
  agent: data_engineer

```

## And finally the relevant portions of my crew.py -

```python
from crewai_tools import NL2SQLTool

local_ollama_llm = LLM(model="ollama/crewai-llama3.2-3b:latest", base_url="http://localhost:11434")

nl2sql = NL2SQLTool(db_uri="mysql://timebill: ****** @127.0.0.1:3306/timebills")

@CrewBase
class Timebillcrew():
    """Timebillcrew crew"""

    agents: List[BaseAgent]
    tasks: List[Task]

    @agent
    def data_engineer(self) -> Agent:
        return Agent(
            config=self.agents_config["data_engineer"],
            llm=local_ollama_llm,
            tools=[nl2sql],
            allow_delegation=False,
            verbose=True,
        )

    
    @task
    def query_task(self) -> Task:
        return Task(
            config=self.tasks_config["query_task"],
            output_file="q.out",
        )

    @crew
    def crew(self) -> Crew:
        """Creates the Timebillcrew crew"""
        return Crew(
            llm=local_ollama_llm,
            agents=self.agents,
            tasks=self.tasks,
            process=Process.sequential,
            verbose=True,
            memory=True,
            share_crew=False,
            output_log_file="crew.log",
            embedder={
                "provider": "ollama",
                "config": {
                    "model": "nomic-embed-text",
                    "task_type": "retrieval_document",
                    "url": "http://localhost:11434/api/embeddings",
                }
            }
        )

```

# And here’s the results of the crew run -

```auto
╭──────────────────────────────────────────────────────── 🤖 Agent Started ────────────────────────────────────────────────────────╮
│ │
│ Agent: Time Billing SQL Data Engineer │
│ │
│ Task: Query employees from a mysql database. To accomplish this retrieve the Time Billing data from the entry_detail table and │
│ show a list of last names. │
│ │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

🚀 Crew: crew
├── 📋 Task: query_task (ID: 260571c5-5971-4304-aabd-f01913edef4c)
│ Status: Executing Task...
│ └── 🔧 Failed NL2SQLTool (1)
└── ✅ Memory Retrieval Completed
    └── Sources Used
        ├── ✅ Long Term Memory (0.53ms)
        ├── ✅ Short Term Memory (49.67ms)
        └── ✅ Entity Memory (14.80ms)
╭─────────────────────────────────────────────────────────── Tool Error ───────────────────────────────────────────────────────────╮
│ │
│ Tool Usage Failed │
│ Name: NL2SQLTool │
│ Error: Arguments validation failed: 1 validation error for NL2SQLToolInput │
│ sql_query │
│ Field required [type=missing, input_value={'query': 'SELECT last_na...9482', 'metadata': {}}}}, input_type=dict] │
│ For further information visit https://errors.pydantic.dev/2.11/v/missing │
│ Tool Args: │
│ │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

```

# Summary

My understanding was that NL2SQLTool expects “natural language” input and it will generate the corresponding SQL. So I avoided providing the SQL directly and instead provided a natural language description of the data desired -

```plaintext
To accomplish this retrieve the {topic} data from the {table_name} table
    and show a list of last names.

```

And I expected that it would produce -

```sql
SELECT last_name FROM entry_detail;

```

If I let the crew run for a while (looping on that error), then it eventually starts spitting out

```auto
╭──────────────────────────────────────────────────── 🔧 Agent Tool Execution ─────────────────────────────────────────────────────╮
│ │
│ Agent: Time Billing SQL Data Engineer │
│ │
│ Thought: Thought: I need to query the entry_detail table in the MySQL database to fetch employee data. │
│ │
│ Using Tool: NL2SQLTool │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────────────────────────────────── Tool Input ───────────────────────────────────────────────────────────╮
│ │
│ "{\"query\": \"SELECT last_name FROM entry_detail\"}" │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭────────────────────────────────────────────────────────── Tool Output ───────────────────────────────────────────────────────────╮
│ │
│ │
│ I encountered an error while trying to use the tool. This was the error: Arguments validation failed: 1 validation error for │
│ NL2SQLToolInput │
│ sql_query │
│ Field required [type=missing, input_value={'query': 'SELECT last_na...9482', 'metadata': {}}}}, input_type=dict] │
│ For further information visit https://errors.pydantic.dev/2.11/v/missing. │
│ Tool NL2SQLTool accepts these inputs: Converts natural language to SQL queries and executes them.. │

```

where it does seem to come up with the correct SQL query but continues erroring out with that validation error.

I must be doing something wrong and could really use some help.
