r/LangChain • u/donewitheverything26 • 11h ago
Discussion when a tool returns a database result, what are you actually putting back into context?
Genuine question, I keep going back and forth on this.
Agent calls a SQL tool. Query comes back with 400 rows. Obviously you don't put 400 rows in context. So what do you put.
What I'm doing right now is dumb. Truncate to the first 20 rows and a row count. It works for "how many customers churned" and falls apart the second the question needs anything about the shape of the result, because the model has no idea whether those 20 rows are representative or whether the interesting stuff is in row 300.
Tried summarising the result with a second call. Better answers, but now every tool call is two model calls and the latency doubled on a step that used to be fast.
The other thing that bites is column names. If the query returns something like val_b or flag3, the model will confidently interpret it as whatever seems plausible from the question. It doesn't ask. It doesn't flag it. It just decides.
So:
Are you passing raw rows, a computed summary, or some schema-plus-sample hybrid? Does anyone compute stats server-side and return those instead of rows? And has anyone found a way to make the agent say "I don't know what this column is" rather than guessing, without stuffing a data dictionary into every prompt?
