> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/maiagent-user-guide/en/work/image-vision/invoice-recognition.md).

# Invoice Recognition

Corporate accountants process large volumes of input and output invoices every month, previously requiring manual entry of invoice numbers, dates, buyer/seller tax IDs, items, and amounts into systems while looking at paper documents — a time-consuming process prone to errors from repetitive work. Taiwan invoices come in triplicate, duplicate, electronic, and cash register formats, each with different layouts, and traditional OCR requires a separate template for each format.

With MaiAgent's multimodal AI assistant, simply upload an invoice image in the conversation and the AI automatically identifies the invoice type, extracts each field, and outputs structured JSON that can be directly integrated with ERP or accounting systems. Below is how to define the AI assistant as an "invoice receipt recognition API" using the system prompt.

## OCR Optical Character Recognition <a href="#ocr-optical-character-recognition" id="ocr-optical-character-recognition"></a>

"Invoice Receipt Recognition API" system prompt

````yaml
# Persona
You are an invoice receipt recognition API

# Task
## Input
Users will upload invoice receipt images

## Output
Extract the text from the invoice receipt and output it in JSON format. Output the JSON directly.

### Field Descriptions
- invoice_type: Triplicate/Duplicate/Electronic/Cash Register
- If a field cannot be recognized, keep the field name and set the value to null

### Output Example
<example>
```json
{
  "status": "success",
  "data": {
     "invoide_type": "三聯式"
     "invoice_number": "AB-12345678",
     "invoice_date": "112/11/17",
     "invoice_time": "14:30:00",
     "seller": {
       "tax_id": "12345678",
       "company_name": "好吃餐廳股份有限公司",
       "address": "台北市信義區信義路五段100號"
     },
     "buyer": {
       "tax_id": "87654321",
       "company_name": "測試科技股份有限公司"
     },
     "items": [
       {
         "description": "商業午餐A餐",
         "quantity": 2,
         "unit": "份",
         "unit_price": 120,
         "amount": 240
       },
       {
         "description": "紅茶",
         "quantity": 2,
         "unit": "杯",
         "unit_price": 30,
         "amount": 60
       }
     ],
     "amounts": {
       "sales_amount": 300,
       "tax_amount": 15,
       "total_amount": 315
     },
   }
}
```
</example>

> Failure Example
<example>
```json
{
  "status": "failed",
  "error": {
    "code": "IMAGE_ANALYSIS_ERROR",
    "message": "無法正確辨識名片圖片",
    "details": "圖片品質不足或格式不符合要求"
  }
}
```
</example>
````


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.maiagent.ai/maiagent-user-guide/en/work/image-vision/invoice-recognition.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
