You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -116,6 +115,26 @@ curl -X POST http://localhost:8000/extract \
116
115
}
117
116
```
118
117
118
+
#### Custom schema constraints
119
+
120
+
The `output_schema` is compiled into a structured output grammar by the Anthropic SDK. This imposes constraints:
121
+
122
+
**Make all fields required.** For missing values, the LLM returns empty string (`""`) for text and `0` for numbers. Do not use nullable/optional fields.
123
+
124
+
**Do not use union types.**`"type": ["string", "null"]` causes an SDK assertion error. `"anyOf"` works but counts against complexity limits.
125
+
126
+
**Keep schemas flat.** Nested objects with multiple fields compound grammar complexity. Use flat keys like `seller_address_street` instead of `seller_address.street`.
127
+
128
+
**Complexity limits** (hard, non-configurable):
129
+
130
+
| Limit | Value |
131
+
|---|---|
132
+
| Optional parameters | 24 total |
133
+
| Union type parameters (`anyOf`, type arrays) | 16 total |
134
+
| Compilation timeout | 180 seconds |
135
+
136
+
Each optional parameter roughly doubles grammar state space. Schemas with >18 optional params will likely timeout.
Copy file name to clipboardExpand all lines: src/app/prompts/extraction.py
+14-5Lines changed: 14 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -7,12 +7,21 @@
7
7
8
8
Rules:
9
9
- Extract ONLY data explicitly present in the document.
10
-
- If a field cannot be found, use null.
10
+
- For fields not found on the invoice: if the schema allows null, return null. If the field is
11
+
required, return an empty string for text fields and 0 for numeric fields.
11
12
- For numeric fields, extract the numeric value without currency symbols or thousand separators.
12
-
- For date fields, use ISO 8601 format (YYYY-MM-DD). Be aware that US invoices use MM/DD/YYYY and European invoices use DD/MM/YYYY. If the format is ambiguous (e.g. 03/04/2025), use other clues such as language, currency, or the fact that most invoices are issued around the current date.
13
-
- For tax identification numbers, correct obvious OCR errors (O→0, l→1, S→5) when the result produces a valid ID.
14
-
- For line items: extract only actual product/service lines, skip subtotals, totals, and summary rows.
13
+
- For date fields, use ISO 8601 format (YYYY-MM-DD). Be aware that US invoices use MM/DD/YYYY and
14
+
European invoices use DD/MM/YYYY. If the format is ambiguous (e.g. 03/04/2025), use other clues such
15
+
as language, currency, or the fact that most invoices are issued around the current date.
16
+
- For tax identification numbers, correct obvious OCR errors (O→0, l→1, S→5) when the result
17
+
produces a valid ID.
18
+
- For line items: extract only actual product/service lines, skip subtotals, totals, and summary
19
+
rows.
15
20
- Be precise — do not infer or guess values that are not clearly stated.
0 commit comments