Skip to content
All case studies
15 Jan 2026

An assistant that reads the database, not the prompt

Building TaskMate's AI assistant with function calling and deliberate context management, so it answers from real data instead of remembering badly.

Role
Sole engineer
Timeline
2025
Stack
Flutter, Node.js, MongoDB, Gemini Flash 2.5, Function calling

Context

TaskMate is a task manager with expense tracking, built as a single product: Flutter app, Node.js API, MongoDB underneath. I built all of it.

The assistant was meant to answer the questions a list cannot: where did my week go, what is still open from last month, how much did I spend on food.

The version that does not work

The obvious implementation is to fetch the user's tasks and expenses, paste them into a prompt, and ask the model to answer.

It demos well and fails in production for two reasons.

It does not fit. A user with a year of history does not fit in a context window. Even if it does, you are paying to send their entire life on every message.

It invents things. Given a large blob of loosely structured data and a question, a model will produce a plausible answer, and plausible is not the same as correct. When it tells someone they spent 4,000 taka on transport and the real figure is 6,200, the feature is worse than useless. It is confidently wrong about the user's own money.

So the design question is not how to prompt better. It is how to stop the model from being the thing that remembers.

Tools, not context stuffing

The assistant runs on Gemini Flash 2.5. The model gets a small set of tools and no data by default.

js
// Shape, not the full implementation.
const tools = [
  {
    name: "query_tasks",
    description: "Fetch the signed in user's tasks in a date range, optionally by status",
    parameters: {
      from: "ISO date", to: "ISO date",
      status: "pending | in_progress | completed"
    }
  },
  {
    name: "query_expenses",
    description: "Fetch the signed in user's expenses in a range, optionally by category",
    parameters: { from: "ISO date", to: "ISO date", category: "string" }
  },
  {
    name: "summarise_totals",
    description: "Aggregate totals for a period, grouped by category or status",
    parameters: { from: "ISO date", to: "ISO date", groupBy: "category | status" }
  }
];

The flow becomes: the user asks a question, the model decides which tool answers it and with what arguments, the backend runs a real MongoDB query, and the result goes back to the model, which turns numbers into a sentence.

The model never sees data it did not ask for, and it never produces a figure that did not come out of the database.

Two rules that make this safe

Scope is set by the server, never by the model. The user id is injected into every query from the authenticated session. It is not a tool parameter, because a parameter is something a model can get wrong, and getting that one wrong means showing one user another user's expenses. The model can choose what to ask. It cannot choose who to ask about.

Tool arguments are validated like any other input. A tool call is untrusted input that happens to have been produced by a model. Date ranges get bounds, enums get checked, and an absurd range is rejected rather than run.

Context management

Sending the whole conversation on every turn is the same mistake as sending the whole database, one layer up. What actually goes into a request:

  • A system prompt with the assistant's role, the tools available, and explicit instruction to answer only from tool results.
  • A short window of recent turns, verbatim, because immediate context ("what about the month before?") depends on exact wording.
  • A rolling summary of everything older, regenerated periodically instead of on every message.
  • A small user frame: timezone, currency, today's date. Without today's date, "this week" is meaningless and the model will guess.

Cost and correctness improve together here, which is worth noticing. The changes that make the assistant cheaper are the same ones that stop it wandering.

Failure handling

The assistant is a feature, not the product. It fails visibly rather than silently.

  • Model unavailable: the app says so and the rest of TaskMate works.
  • Tool returns nothing: it says there is no data for that period. It does not fill the gap.
  • Ambiguous question: it asks one clarifying question rather than picking an interpretation and answering confidently.

That last rule was the hardest to hold, because a model that asks a question feels less impressive in a demo and is far more trustworthy in use.

Results

Shipped on Google Play and the App Store as part of TaskMate.

CONTENT NEEDED: usage of the assistant relative to the rest of the app, or anything you learned from real conversations.

What I would change

Design the tool schemas first, then the prompt. I did the reverse and spent time tuning language to compensate for tools that were shaped wrong. The prompt is the interface to the tools, and an interface written before the thing it wraps is a guess.

The general lesson

An LLM feature is mostly a systems design problem wearing a language interface. The questions that decide whether it works are ordinary engineering questions: what is the source of truth, who sets the scope, what is validated, and what happens on failure. The prompt is the smallest part of it.