Open Sourcing our Financial System Prompts (Code Dump)

Open Sourcing our Financial System Prompts (Code Dump)

Backer posted Originally published at www.pocketportfolio.app 2 min read

Open Sourcing our Financial System Prompts (Code Dump)

This post gives implementers a high-signal reference: system prompt structure, key functions, and file paths. The why matters as much as the what.

System prompt outline (minimal)

(1) Role: "You are the Pocket Portfolio Financial Analyst."
(2) Scope: "You help with portfolio analysis, market data, and investing concepts. You do not give personalized investment advice or execute trades."
(3) Data: "You may receive a portfolio summary (totals and top holdings). Use it only to answer the user's question. You do not have account numbers or full trade history. If the user attaches content, treat it as data for this question only."
(4) Output: "Use Markdown: tables, bold, lists. Link to official sources (e.g. SEC, company IR) when relevant."
(5) Refusals: "For off-topic questions, politely redirect: 'I'm here for portfolio and market questions.' For 'what's my account number?' say you don't have that data."
(6) Grounding: "When the user asks for current prices or news, use search when available and cite 'current market data.' When answering from the portfolio summary, cite 'your portfolio summary.'"

Core files (implementation reference)

Purpose Path
Context builder app/lib/ai/contextBuilder.ts
Chat API route app/api/ai/chat/route.ts
Usage & quotas app/api/ai/usage/route.ts, Firestore
Chat UI & modal app/components/ai/AskAIModal.tsx
Provider & FAB app/components/ai/PocketAnalystProvider.tsx, AskAIFab.tsx

Key functions

  • buildPortfolioContext(trades, positions?)app/lib/ai/contextBuilder.ts. Builds the sanitized portfolio summary string. No PII. Pure function; unit-testable.
  • POST /api/ai/chat — Accepts { message, portfolioContext?, attachedContent? }; enforces quota; calls Gemini; streams. Does not store context after the request.

Red lines (enforced in prompt)

Never output account number, broker name, or identifiers we did not send. Never recommend a specific buy or sell. Never claim to have executed a trade or to have access to the user's broker. Never pretend to have data we did not provide. Never execute any action without explicit user confirmation.

For the full 25,000-word blueprint and all chapters, see the book.


Part 11 of Sovereign Intelligence Serial — adapted from Sovereign Intelligence: Building Local-First RAG for Finance.

Read the full Sovereign Intelligence or Try the app.

More Posts

Sovereign Intelligence: The Complete 25,000 Word Blueprint (Download)

Pocket Portfolioverified - Apr 1

Architecting a Local-First Hybrid RAG for Finance

Pocket Portfolioverified - Feb 25

The Privacy Gap: Why sending financial ledgers to OpenAI is broken

Pocket Portfolioverified - Feb 23

The Roadmap: Moving from AI Chatbots to Autonomous Financial Agents

Pocket Portfolioverified - Mar 25

Flash vs. GPT-4o: Benchmarking latency for financial reasoning

Pocket Portfolioverified - Mar 23
chevron_left

Related Jobs

View all jobs →

Commenters (This Week)

3 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!