Este é o prompt que tenho para minha aplicação de controle financeiro baseado em…
- User
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:
- total_amount (the full value, in 'amount')
- per_person_amount (if calculable, in 'metadata')
- participants (list of names, nicknames, or phone numbers mentioned, in 'related_contacts')
- Add a note in the 'notes' field describing the split (e.g., "Shared with 4 people").
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 } }""" }
Assistant
Aqui está uma versão aprimorada do seu prompt, com melhorias na estrutura, clareza e robustez para lidar com variações de linguagem e situações complexas:
object NlpPrompt { const val PROMPT = """ Analyze the following financial transaction message and extract structured data with high precision. Follow these strict guidelines: 1. **Language Handling**: - All field names and values must be in English. - Preserve the original language, slang, and style in the 'original_content' field. - Handle Brazilian Portuguese variations (e.g., "conto" = 1000, "tão" = 1000, "pila" = money). 2. **Data Extraction Rules**: - Extract all possible financial data while maintaining strict field structure. - For ambiguous cases, make reasonable assumptions but note them in 'notes' and adjust 'confidence'. - Never invent data - use null when information is unavailable. 3. **Special Cases**: - For shared expenses: Calculate per-person amounts when possible and document in 'metadata'. - For installments: Extract both total amount and installment details. - For recurring transactions: Identify frequency patterns (weekly, monthly, etc.). - For time references: Convert relative terms ("ontem", "amanhã") to absolute ISO-8601 dates with timezone offset. 4. **Field Requirements**: - All fields must be included in the response, even if null. - Dates must be in ISO-8601 format with timezone offset (e.g., "2024-07-21T00:00:00-03:00"). - Currency defaults to "BRL" unless specified otherwise. - 'type' must be either "INCOME" or "EXPENSE". 5. **Response Format**: - Return ONLY a valid JSON object with these exact fields: amount, currency, type, category, subcategory, original_content, date, time, payment_method, installments, due_date, payer, payee, related_contacts, urgency, recurrence, location, notes, intent, tags, confidence, metadata 6. **Examples**: Input: "Paguei 50 conto no mercado, parcelado em 3x no cartão" ```json { "amount": 5000, "currency": "BRL", "type": "EXPENSE", "category": "groceries", "subcategory": "supermarket", "original_content": "Paguei 50 conto no mercado, parcelado em 3x no cartão", "date": "2024-07-22T00:00:00-03:00", "time": null, "payment_method": "credit_card", "installments": 3, "due_date": null, "payer": "me", "payee": "supermarket", "related_contacts": [], "urgency": "one-time", "recurrence": "one-time", "location": null, "notes": "5000 BRL total, 3 installments of ~1666.67 BRL", "intent": "purchase", "tags": ["groceries", "installment"], "confidence": 0.95, "metadata": { "installment_value": 1666.67, "total_installments": 3 } }Input: "Recebi 2k do cliente hoje, metade em pix e metade em dinheiro"
{ "amount": 2000, "currency": "BRL", "type": "INCOME", "category": "business", "subcategory": "payment", "original_content": "Recebi 2k do cliente hoje, metade em pix e metade em dinheiro", "date": "2024-07-22T00:00:00-03:00", "time": null, "payment_method": "mixed", "installments": null, "due_date": null, "payer": "client", "payee": "me", "related_contacts": [], "urgency": "one-time", "recurrence": "one-time", "location": null, "notes": "Split payment: 1000 BRL via PIX, 1000 BRL in cash", "intent": "receipt", "tags": ["business", "payment"], "confidence": 0.9, "metadata": { "payment_methods": ["pix", "cash"], "amounts": [1000, 1000] } }- Edge Case Handling:
- For messages with multiple transactions, extract the primary one and note others in 'notes'.
- For incomplete information, make educated guesses but clearly indicate uncertainty in 'notes' and lower 'confidence'.
- For very informal language, prioritize extracting financial data over perfect grammatical parsing.
Respond ONLY with a valid JSON object following the exact structure specified, with all fields present even if null. """ }
Principais melhorias: 1. **Estrutura mais clara**: Organização em seções lógicas com numeração para fácil referência 2. **Tratamento de casos especiais**: Instruções explícitas para situações complexas como parcelamentos, pagamentos mistos e linguagem informal 3. **Exemplos mais robustos**: Incluindo casos com parcelamento e pagamentos mistos 4. **Regras de inferência**: Diretrizes claras sobre quando fazer suposições e como documentá-las 5. **Tratamento de linguagem**: Melhor suporte para gírias e variações regionais 6. **Consistência**: Ênfase na estrutura rígida do JSON e campos obrigatórios 7. **Metadados**: Uso mais estratégico do campo metadata para informações adicionais O prompt agora está mais preparado para lidar com: - Variações linguísticas brasileiras - Situações financeiras complexas - Informações incompletas ou ambíguas - Diferentes formatos de data e valores monetários - Transações compartilhadas ou parceladas- Edge Case Handling:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.