π§ Prompt Engineering β
This page explains how prompt engineering is used to control the AI's behavior β making the agent accurate, deterministic, and safe for managing financial data.
π Why Prompt Engineering Matters β
Without clear instructions, LLMs tend to:
- Hallucinate missing data
- Assume categories or values
- Misinterpret ambiguous queries
To avoid this, we use strict prompts at multiple levels.
π§© System Prompt (AI Agent) β
The main system prompt guides the LangChain Agent behavior and sets hard rules:
text
You are a personal finance assistant. You can record, retrieve, and summarize expenses in a Google Sheet. The sheet contains the following columns:
- Date: The date of the expense (format: YYYY-MM-DD).
- Details: A short description of what the expense was.
- Category: One of the following β Transportation, Breakfast, Lunch, Dinner, Smoke, Donation, Mobile Recharge, Others.
- Amount: The numerical value of the expense in currency.
ONLY use these exact columns. Do not invent new columns or categories.
### When ADDING a new expense:
- Confirm with me before entering.
- Re-confirm or ask questions if the category is unclear.
- Do not assume or autofill missing fields.
### When RETRIEVING or SUMMARIZING:
- Always use tool outputs (from "Get All Expense" or "Get Expense By Category").
- Never generate made-up data or summaries. Only respond based on the actual sheet content.
- If asked to calculate a total, average, or perform arithmetic, use the Calculator tool and sum only the 'Amount' values retrieved from the sheet.
- If no entries are found or inputs are missing, ask for clarification.
If you are unsure β ask. Do not assume.
π Tool Descriptions (Tool-Level Prompts) β
Each tool connected to the agent has its own toolDescription, guiding what it does. This ensures the model doesn't misuse or misunderstand tools.
β Add Expense β
text
Append a new expense entry to the sheet using the columns: Date, Details, Category, Amount. Use only the allowed categories: Transportation, Breakfast, Lunch, Dinner, Smoke, Donation, Mobile Recharge, Others. Confirm details before adding. Do not assume values or categories.
β Get Expense By Category β
text
Retrieve all expense rows from the sheet where the 'Category' column matches the input. Use only the following columns in the response: Date, Details, Category, Amount. Do not add any information beyond what is found in the sheet.
β Get All Expense β
text
Retrieve all entries from the expense sheet. Only return the actual rows from the sheet with columns: Date, Details, Category, Amount. Do not guess or summarize unless explicitly asked.
π§ How the Agent Thinks Hereβs a decision tree the AI agent follows (based on prompt logic):
- Intent: What does the user want?
- Is it an "add" command?
- Is it a "retrieve" request?
- Is it a "calculate" or "summary" question?
- Tool Selection:
- Add β
Add Expense
- Retrieve category β
Get Expense By Category
- Retrieve all β
Get All Expense
- Calculate β
Calculator
(after data fetch)
- Add β
- Chat Logic:
- Always confirms new entries
- Asks questions if input is incomplete
- NEVER makes up data β it always refers to the tools
π‘ Best Practices β
Rule | Why It Matters |
---|---|
Use hardcoded categories | Prevents mismatch or overgeneralization |
Enforce sheet schema | Keeps data clean and export-friendly |
Require confirmation | Stops accidental writes |
Separate tools clearly | Helps LangChain Agent avoid confusion |
Disable hallucination | Prevents AI from inventing numbers or rows |
π Advanced Tips (Optional) β
You can also:
- Add time-based prompt tokens (e.g. "today", "this week") using custom functions
- Add fallback instructions if no entries are found
- Use dynamic prompts to change sheet or context (e.g. personal vs business finance)
β Summary β
Your prompt engineering ensures:
- π Predictable AI behavior
- π Accurate use of your actual data
- π€ Reliable natural language interaction
- π« Zero hallucination or unsafe guesses