GMI · TECHNOLOGY OBSERVATORY // ALL SYSTEMS NOMINAL
ENGINEERED BY LEOPARD DATA

Claude AI Integration

How Grade My Investments leverages Anthropic's Claude AI to deliver intelligent financial analysis, interactive Q&A, and automated report comparison for users.

CLAUDE INTEGRATION
rendering diagram…
flowchart LR
    U([User]):::ext --> FA[File Analysis<br/>right-click Analyze]:::app
    U --> CC[Claude Console<br/>interactive Q-A]:::app
    U --> RC[Report Comparison<br/>select 2 runs]:::app
    U --> DA[Dashboard Ask Claude<br/>portfolio context]:::app
    FA --> DB1[(claudeanalysisjobs<br/>DB queue)]:::data
    CC --> DB1
    DB1 --> P1[Gmi.ClaudeAnalysis<br/>Console service]:::svc
    RC --> DB2[(reportcomparisonjobs<br/>DB queue)]:::data
    DB2 --> P2[Gmi.ReportComparison<br/>Console service]:::svc
    DA --> AZ[Azure Function<br/>inline call]:::svc
    P1 --> API[Anthropic<br/>Messages API]:::ext
    P2 --> API
    AZ --> API
    API --> P1
    API --> P2
    API --> AZ
    P1 --> OUT1[(DOCX - HTML<br/>Blob Storage)]:::data
    P2 --> OUT2[(Comparison DOCX<br/>Blob Storage)]:::data
    AZ --> OUT3[Dashboard<br/>Response]:::app
    classDef app fill:#1f2630,stroke:#C0894E,color:#F3EFE8;
    classDef svc fill:#241c14,stroke:#E2B583,color:#F3EFE8;
    classDef data fill:#22201a,stroke:#C0894E,color:#EBD3AE;
    classDef ext fill:#1b1f27,stroke:#5A616B,color:#C4C0B8;
    classDef sec fill:#1d2733,stroke:#5cc8e0,color:#eafaff;
Four distinct Claude AI features share the Anthropic Messages API but use separate background processors and output paths — file analysis and console Q&A via ClaudeAnalysis.Console, report comparison via ReportComparison.Console, and dashboard queries inline via Azure Functions.

Claude Features at a Glance

Grade My Investments integrates directly with Anthropic's Claude API to provide four distinct user-facing AI capabilities, each designed around a specific workflow:

Claude File Analysis

AI-powered document analysis with DOCX and HTML output saved alongside source files.

Claude Console

Interactive Q&A about your files in real-time with cost tracking per question.

Report Comparison

Compare two report runs and get a narrative change analysis generated by Claude.

Dashboard Ask Claude

Ask Claude questions about your AI Report Dashboard data in real-time.

Claude File Analysis (Wave 3)

Users can right-click any file or folder in the ManageFolders file manager and select "Analyze with Claude" to submit documents for AI-powered analysis. The result is a DOCX file (and a companion HTML file for mobile viewing) saved alongside the original, marked with a purple file indicator in the UI.

How It Works
1. User right-clicks files or folders in ManageFolders and selects "Analyze with Claude"
2. Cost estimation is calculated and displayed — user approves before proceeding
3. Analysis requests are queued in the database (claudeanalysisjobs / claudeanalysisrequests)
4. The Gmi.ClaudeAnalysis.Console background service picks up jobs in batches of 5
5. Files are sent to the Anthropic Claude API with concurrency of 3 and retry logic (3 attempts with exponential backoff)
6. Results are converted to DOCX and HTML, then saved alongside the original source files in blob storage
Background Processor
Gmi.ClaudeAnalysis.Console
  • Queue-based: Database-driven job queue
  • Batch size: 5 jobs per poll cycle
  • Concurrency: 3 parallel API calls
  • Retry: 3 attempts with exponential backoff
  • Rate limiting: Anthropic API throttle handling
  • Stale recovery: 30 min timeout for stuck requests
Supported File Types
Documents
  • PDF
  • DOCX / DOC
  • TXT / MD
  • JSON / XML
Data & Images
  • CSV / XLSX / XLS
  • PNG / JPG
  • GIF / BMP
  • WEBP
Content Extraction
  • PDF: PdfPig library
  • DOCX/XLSX: OpenXml SDK
  • Text files: UTF-8 encoding
  • Images: Claude Vision API (base64)
DOCX + HTML Output
  • DOCX generated with DocumentFormat.OpenXml
  • HTML generated with Markdig for mobile viewing
  • Markdig converts Claude's Markdown response
  • Purple file indicator in the file manager
  • Available on ClientWeb, AdminWeb, and MAUI Mobile

Claude Console (Wave 3)

The Claude Console is an interactive chat dialog that lets users ask questions about their files in real-time. Rather than submitting a batch analysis, users open a conversation with Claude about a specific file or an entire folder.

Features
  • Interactive chat dialog for file Q&A
  • Supports single files or entire folders (recursively collects all file IDs)
  • Real-time cost estimation per question
  • Token and cost tracking on each response
  • Keyboard support: Enter to send, Shift+Enter for new line
  • Available via toolbar button and right-click context menu
How It Works
1. User selects a file or folder and opens Claude Console
2. File content is extracted and sent as context
3. User types a question — cost estimate shown before submission
4. Claude responds with analysis — tokens and cost displayed
5. User can ask follow-up questions in the same session

Report Comparison with Claude (Wave 4)

Report Comparison lets users select two ML report generation runs from the same symbol list group and have Claude produce a detailed narrative analysis of what changed between them. Users can also add their own custom questions to be answered as part of the comparison.

Dialog Flow
Select Group
Pick a symbol list group
Select 2 Runs
Choose runs to compare
Custom Questions
Add specific questions
Estimate Cost
Review before submitting
Submit
Queue for processing
Background Processor
Gmi.ReportComparison.Console
  • Batch size: 3 jobs per poll cycle
  • Concurrency: 2 parallel API calls
  • Stale timeout: 60 minutes
  • Downloads both Excel file sets from blob storage
  • Sends to Claude with structured comparison prompt
  • Generates DOCX comparison analysis
DOCX Output Sections (11)
  1. Executive Summary
  2. Symbols Added
  3. Symbols Removed
  4. Movers & Shakers
  5. Improved Positions
  6. Deteriorated Positions
  7. New Risk Alerts
  8. Opportunities
  9. Portfolio-Level Trend
  10. Actionable Recommendations
  11. Your Questions Answered
Jobs Panel: Users can track comparison jobs in real-time via a dedicated jobs panel with auto-polling status updates. Custom questions typed by the user are included in section 11 ("Your Questions Answered") of the output document.

Dashboard Ask Claude

The AI Report Dashboard includes an "Ask Claude" feature that lets users ask questions about their portfolio data directly from the dashboard view. Claude receives the full dashboard context (financial data, ML health scores, anomalies, forecasts) and provides specific, actionable analysis.

Features
  • Ask questions about any dashboard level (portfolio, sector, or symbol)
  • Full dashboard context sent automatically
  • Default analysis provided when no specific question is asked
  • Token and cost tracking on each response
  • Admin notification on each dashboard Claude request
How It Works
1. User clicks "Ask Claude" on the Report Dashboard
2. Dashboard context (data, scores, forecasts) is gathered
3. User optionally types a specific question
4. Claude Sonnet 4.6 responds with analysis and insights
5. Response with token usage and cost is displayed
Model: Dashboard Ask Claude uses Claude Sonnet 4.6 by default. Available on ClientWeb, AdminWeb, and MAUI Mobile.

Technical Architecture

Claude integration is built around two background .NET console applications plus inline API calls in Azure Functions — a deliberate separation of concerns that keeps file analysis, report comparison, and real-time Q&A independent.

Gmi.ClaudeAnalysis.Console

File Analysis & Console Q&A

gmi-claudeanalysis.service
Gmi.ReportComparison.Console

Report Comparison Processing

gmi-reportcomparison.service
Shared Infrastructure
  • Azure Blob Storage for file I/O
  • DocumentFormat.OpenXml + Markdig for DOCX generation
  • Markdig HTML report generation for mobile viewing
  • Anthropic Messages API (v1/messages)
  • Systemd services on Azure VM
  • Environment variable configuration
  • Token-based billing integration
  • Admin email notifications on failures and usage
Database Tables
Feature Tables
File Analysis claudeanalysisjobs, claudeanalysisrequests
Report Comparison reportcomparisonjobs, reportcomparisonjobsymbollists

Model Options

Users choose which Claude model to use when submitting analysis or comparison jobs. Each model offers a different balance of quality, speed, and cost:

Model Use Case Input Cost Output Cost
Claude Sonnet 4.6 Recommended — best balance of quality and cost $5.40 / 1M tokens $27.00 / 1M tokens
Claude Haiku 4.5 Faster, cheaper — good for large files $1.44 / 1M tokens $7.20 / 1M tokens
Claude Opus 4.7 Most thorough — deepest analysis $27.00 / 1M tokens $135.00 / 1M tokens
Grade My Investments applies an 80% markup over Anthropic base costs. The prices shown above reflect what users pay.

API Endpoints

A total of 17 API endpoints power the Claude integration across file analysis, report comparison, and the report dashboard:

File Analysis (8 endpoints)
  • Estimate — Calculate cost before submission
  • Submit — Queue analysis job
  • Jobs — List user's analysis jobs
  • Job Detail — Get individual job status/results
  • Cancel — Cancel a pending analysis job
  • Dismiss — Dismiss a completed job from the list
  • Console Estimate — Cost estimate for a console question
  • Console Ask — Submit a console question
Report Comparison (8 endpoints)
  • Groups — List available symbol list groups
  • Runs — List report runs for a group
  • Estimate — Calculate comparison cost
  • Submit — Queue comparison job
  • Jobs — List user's comparison jobs
  • Job Detail — Get comparison job status/results
  • Cancel — Cancel a pending comparison job
  • Dismiss — Dismiss a completed job from the list
Report Dashboard (1 endpoint)
  • DashboardAskClaude — Ask Claude about dashboard data with full portfolio context
Key Stats
  • Background Processors 2
  • API Endpoints 17
  • Claude Models 3
  • AI Features 4
  • Supported File Types 16+
Claude API Integration
  • Anthropic Messages API
  • Native PDF support
  • Vision API for images
  • Structured prompts
Billing Integration
  • Token-based billing (input + output)
  • Cost estimation before submission
  • 80% markup over Anthropic base cost
  • Charge reversal on failure
Security
  • API key in Azure Key Vault / env vars
  • No user data sent to third parties beyond Anthropic API
  • Fail-open validation