# CrewAI NL2SQL Tool Truncates SQL Queries

**URL:** <https://community.crewai.com/t/crewai-nl2sql-tool-truncates-sql-queries/6113>\
**Category:** CrewAI Community Support\
**Tags:** tools\_issues, crewai\
**Created:** [June 5, 2025, 7:57am UTC](https://community.crewai.com/t/crewai-nl2sql-tool-truncates-sql-queries/6113 "2025-06-05T07:57:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brinil\_John](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/brinil_john/32/3015_2.png) [@Brinil\_John](https://community.crewai.com/u/Brinil_John)\
**Post date:** [June 5, 2025, 7:57am UTC](https://community.crewai.com/t/crewai-nl2sql-tool-truncates-sql-queries/6113/1 "2025-06-05T07:57:20Z")

</div>

I am using this crewai’s Nl2SQL tool for a SQL query generation task, sometimes the tool’s behaves like the `NL2SQLTool` receives the full SQL query as seen in the Tool Input, but the debug log prints only a truncated portion, often stopping at `...AND date =`, leading to execution failure. Behaviour Differs Between Standalone and FastAPI: The same agent, prompt, and code work perfectly when executed as a standalone script but fail when used within a FastAPI-based environment using `.kickoff()`. Why is it happening?

- You can see in the screenshot clearly that the tool input has the full SQL query, but the output shows that only half of the query is used during execution
- I opened the tools code and used a print statement there, and that also clearly shows that only half query is going to the tool while execution.  
 ![sql](https://us1.discourse-cdn.com/flex025/uploads/crewai/original/2X/b/bd4b0619304183c1bb6c3158b3db1e99de1c659f.png)

---

<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 12, 2025, 6:03am UTC](https://community.crewai.com/t/crewai-nl2sql-tool-truncates-sql-queries/6113/2 "2025-09-12T06:03:19Z")

</div>

Hi @Brinil_John, sorry I don’t have an answer but I do have a question - how did you get NL2SQLTool to populate sql\_query? I’ve [posted my question in detail](https://community.crewai.com/t/nl2sqltool-returning-only-validation-errors/7031) and it’s clear that you’ve got it working, albeit with some truncation issues under certain conditions unfortunately…

---

<div class="post-metadata">

**Author:** ![Brinil\_John](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/brinil_john/32/3015_2.png) [@Brinil\_John](https://community.crewai.com/u/Brinil_John)\
**Post date:** [September 12, 2025, 6:49am UTC](https://community.crewai.com/t/crewai-nl2sql-tool-truncates-sql-queries/6113/3 "2025-09-12T06:49:23Z")

</div>

Add this below given line in your task description in the top:

Use NL2SQLTool correctly by passing the input as ‘sql\_query’: \<your\_query\>.

```
    Always return the SQL query as a JSON object using this format:

    {{

    "sql_query": "<FULL SQL QUERY>"

    }}

```

---

<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 15, 2025, 7:44pm UTC](https://community.crewai.com/t/crewai-nl2sql-tool-truncates-sql-queries/6113/4 "2025-09-15T19:44:00Z")

</div>

Thanks @Brinil_John, I’m not sure I understood your reply. I tried several variations on your suggestion but none of them allowed me to get beyond that “validation error”.

```auto
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 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...6956', 
'metadata': {}}}}, input_type=dict] │
│ For further information visit https://errors.pydantic.dev/2.11/v/missing │
│ Tool Args: │
│ │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

```

When you say \<FULL SQL QUERY\> are you saying that I should enter the SQL query myself or let NL2SQLTool generate it? I ask because the NL2SQLTool docs say “_This tool is used to convert natural language to SQL queries. When passed to the agent it will generate queries and then use them to interact with the database_.”

It sounded to me like you meant I should update my tasks.yaml file to look like -

```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.
    Always return the SQL query as a JSON object using this format:
    {{
    "sql_query": "SELECT last_name FROM entry_detail;"
    }}
  expected_output: >
    The {topic} employee data will be output in markdown format.
  agent: data_engineer

```

but that continues to generate that validation error.

---

<div class="post-metadata">

**Author:** ![Brinil\_John](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/brinil_john/32/3015_2.png) [@Brinil\_John](https://community.crewai.com/u/Brinil_John)\
**Post date:** [September 18, 2025, 4:18am UTC](https://community.crewai.com/t/crewai-nl2sql-tool-truncates-sql-queries/6113/5 "2025-09-18T04:18:21Z")

</div>

Yes add that as the starting line of your task description also add this line in the top of your task:

”Use NL2SQLTool correctly by passing the input as ‘sql\_query’: \<your\_query\>.”
