Skip to content

🧠 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):

  1. Intent: What does the user want?
    • Is it an "add" command?
    • Is it a "retrieve" request?
    • Is it a "calculate" or "summary" question?
  2. Tool Selection:
    • Add β†’ Add Expense
    • Retrieve category β†’ Get Expense By Category
    • Retrieve all β†’ Get All Expense
    • Calculate β†’ Calculator (after data fetch)
  3. Chat Logic:
    • Always confirms new entries
    • Asks questions if input is incomplete
    • NEVER makes up data β€” it always refers to the tools

πŸ’‘ Best Practices ​

RuleWhy It Matters
Use hardcoded categoriesPrevents mismatch or overgeneralization
Enforce sheet schemaKeeps data clean and export-friendly
Require confirmationStops accidental writes
Separate tools clearlyHelps LangChain Agent avoid confusion
Disable hallucinationPrevents 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