Build notesAI agent2026

InsightAI

Answers plain-English questions about an e-commerce database with safe, read-only MongoDB queries.

Won’tNever writes to your database, and never invents a number.

Role
Personal project
When
Mar – Jul 2026
Built with
PythonFastAPIMongoDB AtlasGroqGeminiVanilla JS
Links
insightai · ask the database

? Top five product categories by revenue since July

→ intent: revenue · planner writes a JSON plan, never a raw query

[

{ $match: { orderDate: { $gte: "2026-07-01" } } },

{ $group: { _id: "$category", revenue: { $sum: "$total" } } },

{ $sort: { revenue: -1 } },

{ $limit: 5 }

]

✓ read-only operation · no PII fields · schema-validated

Illustrative query. The checks shown are the project’s real safety rules.

Why it exists

Business teams want answers like “how much revenue did we make this month?” without writing queries. But letting a language model write raw database queries invites injection, accidental writes and leaked customer data.

What it does

  • A four-stage agent: intent detector, query planner, query executor and insight generator.
  • Conversation memory, so “explain the last result” works without another query.
  • Groq as the model, with automatic fallback to Gemini when a quota runs out.

What it won’t do

  • The model never writes a raw query. It writes a JSON plan that the planner checks.
  • Only aggregate, count, find_one and distinct are allowed. Nothing can write.
  • Name, email, phone and password fields are blocked at the schema level.
  • Insights only use values from the database result, so numbers can’t be invented.
  • Every API route needs an admin key.

How it works

The model never touches the database directly. The executor runs a schema-validated, read-only aggregation with a timeout, and the insight generator works only from what came back.

By the numbers

70%Less time writing queries
4Agent stages
4Allowed read operations
Next build notesOutreach Agent

Finds local businesses, drafts a pitch and sends only what passes its checks.