👉 Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/receipt_expense_scanner
AI Receipt & Expense Scanner for C# .NET Applications
🎯 Purpose of the Demo
AI Receipt & Expense Scanner demonstrates how to use LM-Kit.NET to extract structured expense data from receipts entirely on local hardware. Feed it any receipt and get back structured JSON with store info, line items, totals, tax breakdown, payment details, and an automatic expense category.
The sample shows how to:
- Use
TextExtractionto extract structured data from receipt text. - Define extraction schemas with
TextExtractionElementincluding line item arrays. - Automatically categorize expenses (Meals, Office Supplies, Travel, Groceries, etc.).
- Parse text content with
SetContent(string)or load documents/images withAttachment.
Why a Local Receipt Scanner with LM-Kit.NET?
- Financial data stays private: process expense receipts without uploading to cloud services.
- One API call: a single
Parse()call extracts all receipt data. No agents, no chaining. - Line item detail: each purchased item extracted with quantity, unit price, and total.
- Works offline: no API keys, no internet connection required.
👥 Who Should Use This Demo
- Finance Teams: automate receipt processing for expense reports.
- Accountants: extract structured data from receipts for bookkeeping.
- Small Business Owners: digitize paper receipts for tax preparation.
- Expense Management Developers: integrate local receipt scanning into expense apps.
- Developers: learn the
TextExtractionAPI with nested array elements for line items.
🚀 What Problem It Solves
- Manual data entry: eliminate typing receipt details into expense reports.
- Data privacy: process receipts with sensitive financial data without cloud exposure.
- Categorization: automatically classify expenses into accounting categories.
- Integration: produce JSON output ready for accounting software or ERP systems.
💻 Demo Application Overview
Console app that:
- Lets you choose from multiple models optimized for text extraction.
- Downloads models if needed, with live progress updates.
- Creates a TextExtraction instance with a receipt-specific schema.
- Enters an interactive loop where you can:
- Type
sampleto scan a built-in grocery store receipt. - Enter a file path to scan your own receipt (.txt, .pdf, .png, .jpg).
- View the extracted expense data with color-coded output.
- View the full JSON output for integration.
- Type
- Loops until you type
q.
Key Features
- Line Item Extraction: Each item parsed with description, quantity, unit price, and total.
- Tax Breakdown: Tax rate and tax amount extracted separately.
- Auto-Categorization: AI suggests the expense category for accounting.
- Built-In Sample: Realistic grocery receipt for instant demo.
- JSON Output: Machine-readable structured data for any accounting system.
- Zero Configuration: No API keys, no cloud accounts, no external dependencies.
🏗️ Architecture
┌─────────────────────────────────────────────────┐
│ Receipt (text, PDF, image) │
└───────────────────┬─────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────┐
│ TextExtraction │
│ │
│ Schema: │
│ ├── Store Name (String) │
│ ├── Store Address (String) │
│ ├── Date (Date) │
│ ├── Time (String) │
│ ├── Items (Array) │
│ │ ├── Description, Quantity │
│ │ └── Unit Price, Total │
│ ├── Subtotal (Float) │
│ ├── Tax Rate / Tax Amount (Float) │
│ ├── Discount (Float) │
│ ├── Total (Float) │
│ ├── Payment Method (String) │
│ ├── Transaction ID (String) │
│ └── Expense Category (String) │
│ │
└───────────────────┬─────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────┐
│ Structured Expense Report │
│ (formatted display + JSON) │
└─────────────────────────────────────────────────┘
Extraction Schema
| Field | Type | Description |
|---|---|---|
| Store Name | String | Name of the store or business |
| Store Address | String | Full address of the store |
| Date | Date | Transaction date |
| Time | String | Transaction time |
| Items | Array | Description, quantity, unit price, line total |
| Subtotal | Float | Total before tax and discounts |
| Tax Rate | String | Applied tax rate |
| Tax Amount | Float | Total tax charged |
| Discount | Float | Discount applied |
| Total | Float | Final amount paid |
| Payment Method | String | Cash, card, etc. |
| Transaction ID | String | Receipt reference number |
| Expense Category | String | AI-suggested category |
Code Highlights
using LMKit.Extraction;
using LMKit.Model;
LM model = LM.LoadFromModelID("qwen3:8b");
var textExtraction = new TextExtraction(model);
textExtraction.Elements = new List<TextExtractionElement>
{
new("Store Name", ElementType.String, "Name of the store."),
new("Date", ElementType.Date, "Transaction date."),
new("Items",
new List<TextExtractionElement>
{
new("Description", ElementType.String, "Item name."),
new("Quantity", ElementType.Integer, "Quantity purchased."),
new("Unit Price", ElementType.Float, "Price per unit."),
new("Total", ElementType.Float, "Line total.")
},
isArray: true,
"Purchased items."
),
new("Total", ElementType.Float, "Final amount paid."),
new("Expense Category", ElementType.String, "Suggested category."),
// ... more elements
};
textExtraction.SetContent(receiptText);
var result = textExtraction.Parse();
Console.WriteLine(result.Json);
⚙️ Getting Started
Prerequisites
- .NET 8.0 or later
- Sufficient VRAM for the selected model (6-18 GB depending on model choice)
Download
git clone https://github.com/LM-Kit/lm-kit-net-samples
cd lm-kit-net-samples/console_net/receipt_expense_scanner
Run
dotnet build
dotnet run
Then:
- Select a model from the menu, or paste a custom model URI.
- Wait for the model to download (first run) and load.
- Type
sampleto try the built-in receipt, or enter a file path. - View the extracted expense data and JSON output.
- Type
qto exit.
🔧 Troubleshooting
Incomplete line items
- Try a larger model (12B+) for better accuracy on receipts with many items.
- Ensure the receipt text is complete and legible.
Image-based receipts
- For receipt photos or scans, use vision-capable models or OCR preprocessing.
- See the
invoice_data_extractiondemo for image-based extraction.
Incorrect totals
- The model extracts values as-is from the receipt, it does not recalculate.
- Verify the original receipt data is correct.
🚀 Extend the Demo
- Batch scanning: process a folder of receipts and generate an expense summary.
- Budget tracking: aggregate extracted totals by category over time.
- Accounting integration: export JSON to QuickBooks, Xero, or FreshBooks.
- Multi-currency: extract and convert currency for international receipts.
- Receipt images: combine with vision models for scanning physical receipts.
📚 Additional Resources
- LM-Kit.NET Documentation
- TextExtraction API Reference
- TextExtractionElement API Reference
- Attachment API Reference
- LM-Kit Samples Repository
📚 Related Content
- How-To: Extract Structured Data: General guide to defining extraction schemas with nested arrays for line items.
- How-To: Extract Invoice Data from Documents: Similar extraction workflow applied to invoices with OCR support.
- Glossary: Structured Data Extraction: Explains schema-driven extraction concepts used for receipt parsing.
- Invoice Data Extraction Demo: Companion demo for extracting structured data from invoice documents.