Este é o prompt que tenho para minha aplicação de controle financeiro baseado em…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Este é o prompt que tenho para minha aplicação de controle financeiro baseado em whatsapp e com backend em spring boot e ts na camada de nlp. Melhore o prompt pensando em como não perder nenhum campo, nem adicionar outros sem necessidade, mas melhorar o prompt em si fazendo com que quaisquer situações ou estilos de escritas por esotericos que sejam possam ser parseados.
object NlpPrompt { const val PROMPT = """ Analyze the following sentence and extract as much structured financial transaction data as possible. All field names and values must be in English, except for the 'original_content' field, which should preserve the user's original language and style. Do not return or store any image or document files, only metadata and extracted text if available. All date/time fields must be in ISO-8601 format with offset, e.g., "2024-07-21T00:00:00-03:00".
If the expense is shared or divided among multiple people, extract:
Return a JSON with these fields (use null if not available): amount, currency (default "BRL"), type ("INCOME" or "EXPENSE"), category, subcategory, original_content, date (ISO-8601 with offset), time, payment_method, installments, due_date (ISO-8601 with offset), payer, payee, related_contacts (names, nicknames or phone numbers), urgency, recurrence, location, notes, intent, tags, confidence (0 to 1), metadata (object with any relevant file or context info).
Respond ONLY with a valid JSON object, with all fields listed above, even if some are null.
Examples:
Input: "vó me deu 20tão ontem"
{
"amount": 20,
"currency": "BRL",
"type": "INCOME",
"category": "gift",
"subcategory": null,
"original_content": "vó me deu 20tão ontem",
"date": "2024-07-21T00:00:00-03:00",
"time": null,
"payment_method": "cash",
"installments": null,
"due_date": null,
"payer": "grandmother",
"payee": null,
"related_contacts": [],
"urgency": "one-time",
"recurrence": "one-time",
"location": null,
"notes": null,
"intent": "gift",
"tags": ["gift", "family", "grandmother"],
"confidence": 0.95,
"metadata": null
}
Input: "Vamos comer pizza hoje, 100 reais dividido para 4 pessoas."
{
"amount": 100,
"currency": "BRL",
"type": "EXPENSE",
"category": "food",
"subcategory": "pizza",
"original_content": "Vamos comer pizza hoje, 100 reais dividido para 4 pessoas.",
"date": "2024-07-22T00:00:00-03:00",
"time": null,
"payment_method": null,
"installments": null,
"due_date": null,
"payer": "me",
"payee": "pizzeria",
"related_contacts": [],
"urgency": "one-time",
"recurrence": "one-time",
"location": null,
"notes": "Shared with 4 people. Each pays 25.",
"intent": "food",
"tags": ["pizza", "food", "friends"],
"confidence": 0.85,
"metadata": { "per_person_amount": 25, "participants": 4 }
}
Input: "bora nós quatro no cinema, tá 15 conto cada, eu pago hoje à noite"
{
"amount": 60,
"currency": "BRL",
"type": "EXPENSE",
"category": "leisure",
"subcategory": "cinema",
"original_content": "bora nós quatro no cinema, tá 15 conto cada, eu pago hoje à noite",
"date": "2024-07-22T00:00:00-03:00",
"time": "night",
"payment_method": "cash",
"installments": null,
"due_date": null,
"payer": "me",
"payee": "cinema",
"related_contacts": [],
"urgency": "one-time",
"recurrence": "one-time",
"location": null,
"notes": "Split with four friends. Each pays 15.",
"intent": "leisure",
"tags": ["cinema", "leisure", "friends"],
"confidence": 0.9,
"metadata": { "per_person_amount": 15, "participants": 4 }
}
""" }
Here's an optimized and robust version of your NLP prompt**, significantly improved for resilience, clarity, and parsing capability across diverse, informal, or esoteric user inputs — while strictly preserving the required JSON structure and field integrity.
The goal is to:
object NlpPrompt {
const val PROMPT = """
Analyze the provided text and extract structured financial transaction data with maximum precision. The input may be informal, contain slang, abbreviations, emojis, typos, or incomplete grammar — treat all variations as valid natural language.
Your task is to parse ANY form of financial mention — income, expense, promise, plan, reminder, or split — and extract only the fields defined below. All output must be in English, except 'original_content', which must remain exactly as written.
### Rules:
1. Output ONLY a single valid JSON object with ALL the fields listed below, even if their value is null.
2. Dates and times must be in ISO-8601 format with timezone offset (e.g., "2024-07-21T19:30:00-03:00"). Infer timezone as -03:00 (Brasília Time) unless specified.
3. If a date is relative (e.g., "yesterday", "hoje", "amanhã"), calculate it based on today's date: 2024-07-22.
4. Default currency is "BRL" unless another is clearly indicated (e.g., USD, €).
5. 'amount' must reflect the total transaction value. For shared expenses, compute total = per-person × number of people.
6. If expense/income is split:
- Set 'amount' to the full amount
- Include 'per_person_amount' in metadata if known
- List all mentioned participants in 'related_contacts' (names, nicknames, numbers)
- Add a note like "Split with X people. Each pays Y."
7. Infer 'payer' and 'payee' from context (e.g., “eu pago” → payer: "me"; “me deram” → payee: "me").
8. Use conservative 'confidence' scores:
- 0.9–1.0: Clear, complete info
- 0.7–0.8: Some ambiguity but logical inference
- 0.5–0.6: Major gaps, high uncertainty
- <0.5: Only if nearly impossible to interpret
9. 'intent' should capture the primary financial purpose (e.g., "gift", "food", "transport").
10. 'tags' should include relevant keywords derived from context (max 5).
11. Never invent data. Only extract what is implied or stated.
### Fields to Return (all required, use null if unavailable):
- amount: number | null
- currency: string (default "BRL")
- type: "INCOME" | "EXPENSE" | null
- category: string | null
- subcategory: string | null
- original_content: string (preserve original language, spelling, style)
- date: string (ISO-8601 with offset) | null
- time: string ("morning", "afternoon", "night", "dawn") or precise time if given | null
- payment_method: string ("cash", "credit_card", "debit_card", "pix", "bank_transfer", etc.) | null
- installments: number | null
- due_date: string (ISO-8601 with offset) | null
- payer: string (e.g., "me", "John", "Maria") | null
- payee: string (e.g., "Uber", "market", "Ana") | null
- related_contacts: array of strings (names, nicknames, phone numbers) | empty array if none
- urgency: "urgent" | "normal" | "one-time" | null
- recurrence: "one-time" | "weekly" | "monthly" | "daily" | "yearly" | null
- location: string | null
- notes: string | null
- intent: string | null
- tags: array of strings | empty array
- confidence: number (0.0 to 1.0)
- metadata: object | null (use for per_person_amount, participants count, file context, etc.)
### Important:
- Do NOT include explanations, comments, or code blocks.
- Respond ONLY with the JSON object.
- Ensure the JSON is valid and contains every field listed above.
### Examples:
Input: "vó me deu 20tão ontem"
```json
{
"amount": 20,
"currency": "BRL",
"type": "INCOME",
"category": "gift",
"subcategory": null,
"original_content": "vó me deu 20tão ontem",
"date": "2024-07-21T00:00:00-03:00",
"time": null,
"payment_method": "cash",
"installments": null,
"due_date": null,
"payer": "grandmother",
"payee": null,
"related_contacts": [],
"urgency": "one-time",
"recurrence": "one-time",
"location": null,
"notes": null,
"intent": "gift",
"tags": ["gift", "family", "grandmother"],
"confidence": 0.95,
"metadata": null
}
Input: "Vamos comer pizza hoje, 100 reais dividido para 4 pessoas."
{
"amount": 100,
"currency": "BRL",
"type": "EXPENSE",
"category": "food",
"subcategory": "pizza",
"original_content": "Vamos comer pizza hoje, 100 reais dividido para 4 pessoas.",
"date": "2024-07-22T00:00:00-03:00",
"time": null,
"payment_method": null,
"installments": null,
"due_date": null,
"payer": "me",
"payee": "pizzeria",
"related_contacts": [],
"urgency": "one-time",
"recurrence": "one-time",
"location": null,
"notes": "Shared with 4 people. Each pays 25.",
"intent": "food",
"tags": ["pizza", "food", "friends"],
"confidence": 0.85,
"metadata": {
"per_person_amount": 25,
"participants": 4
}
}
Input: "bora nós quatro no cinema, tá 15 conto cada, eu pago hoje à noite"
{
"amount": 60,
"currency": "BRL",
"type": "EXPENSE",
"category": "leisure",
"subcategory": "cinema",
"original_content": "bora nós quatro no cinema, tá 15 conto cada, eu pago hoje à noite",
"date": "2024-07-22T00:00:00-03:00",
"time": "night",
"payment_method": "cash",
"installments": null,
"due_date": null,
"payer": "me",
"payee": "cinema",
"related_contacts": [],
"urgency": "one-time",
"recurrence": "one-time",
"location": null,
"notes": "Split with four friends. Each pays 15.",
"intent": "leisure",
"tags": ["cinema", "leisure", "friends"],
"confidence": 0.9,
"metadata": {
"per_person_amount": 15,
"participants": 4
}
}
Now process the next input accordingly. """ }
---
### ✅ Key Improvements:
| Feature | Enhancement |
|-------|-------------|
| **Robustness** | Explicit handling of slang, typos, fragments, emojis, and ambiguity |
| **Date Handling** | Clear rule for relative dates using fixed reference (`2024-07-22`) |
| **Confidence Guidance** | Scaled scoring guidance prevents overconfidence |
| **Shared Expenses** | Better logic for total vs per-person, metadata usage |
| **Field Integrity** | Enforced presence of all fields, no omissions |
| **Clarity** | Structured rules, bullet points, and separation of concerns |
| **Safety** | Prevents hallucination with "never invent data" directive |
| **Localization** | Assumes BRT timezone and BRL currency as defaults |
---
This version will perform significantly better with messy WhatsApp-style messages like:
- `"fiz uma venda de 80 pila pelo pix agora"`
- `"amanhã vou pagar 200 no mercado em 4x"`
- `"aquele dinheiro que o pedro me deve, 50 conto, vence amanhã"`
- `"ganhei 100 USD da tia em NY ontem de manhã"`
And still produce consistent, machine-readable JSON.
Let me know if you'd like a **version that supports multi-transaction detection** (i.e., multiple expenses/incomes in one message).