@docrouter/mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,472 @@
1
+ # DocRouter Prompt Configuration Guide
2
+
3
+ ## Overview
4
+
5
+ Prompts in DocRouter are instructions that guide AI language models to extract structured information from documents. A well-configured prompt ensures consistent, accurate data extraction across your document processing pipeline.
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [What is a Prompt?](#what-is-a-prompt)
10
+ 2. [Prompt Structure](#prompt-structure)
11
+ 3. [Associating Schemas](#associating-schemas)
12
+ 4. [Selecting Language Models](#selecting-language-models)
13
+ 5. [Tagging and Organization](#tagging-and-organization)
14
+ 6. [Best Practices](#best-practices)
15
+ 7. [API Integration](#api-integration)
16
+ 8. [Examples](#examples)
17
+
18
+ ---
19
+
20
+ ## What is a Prompt?
21
+
22
+ A prompt is a text instruction that tells an AI model what to do with a document. In DocRouter, prompts:
23
+
24
+ - Guide LLMs to extract specific data from documents
25
+ - Can be linked to schemas for structured output validation
26
+ - Can be tagged to automatically process specific document types
27
+ - Support multiple AI models (OpenAI, Anthropic Claude, Google Gemini, etc.)
28
+
29
+ ---
30
+
31
+ ## Prompt Structure
32
+
33
+ ### Basic Components
34
+
35
+ Every prompt in DocRouter has the following components:
36
+
37
+ | Component | Required | Description |
38
+ |-----------|----------|-------------|
39
+ | **Name** | Yes | Human-readable identifier for the prompt |
40
+ | **Content** | Yes | The instruction text sent to the AI model |
41
+ | **Schema** | No | Optional JSON schema for structured output |
42
+ | **Model** | No | AI model to use (defaults to `gemini-2.0-flash`) |
43
+ | **Tags** | No | Document tags that trigger this prompt |
44
+
45
+ ### Prompt Content
46
+
47
+ The prompt content is the core instruction sent to the AI model. It should:
48
+
49
+ - Be clear and specific about what data to extract
50
+ - Provide context about the document type
51
+ - Include examples when helpful
52
+ - Reference the schema fields if one is associated
53
+
54
+ **Example:**
55
+ ```
56
+ Extract key information from this invoice document.
57
+
58
+ Please identify:
59
+ - Invoice number
60
+ - Invoice date
61
+ - Vendor name and address
62
+ - Customer name
63
+ - Line items with quantities and prices
64
+ - Subtotal, tax, and total amounts
65
+ - Payment terms
66
+
67
+ Return the data in the format specified by the schema.
68
+ ```
69
+
70
+ ---
71
+
72
+ ## Associating Schemas
73
+
74
+ ### Why Use Schemas?
75
+
76
+ Linking a schema to a prompt ensures:
77
+
78
+ - **Structured output**: Data is returned in a consistent JSON format
79
+ - **Type validation**: Fields are validated against the schema
80
+ - **100% adherence**: With strict mode, the LLM output always matches the schema
81
+ - **No post-processing**: Output is immediately usable by your application
82
+
83
+ ### How to Associate a Schema
84
+
85
+ When creating or editing a prompt, you can optionally select a schema from the dropdown menu. The system will:
86
+
87
+ 1. Link the prompt to the schema's `schema_id`
88
+ 2. Store the current `schema_version` for versioning
89
+ 3. Use the latest version of the schema when processing documents
90
+ 4. Display schema fields in the prompt editor for reference
91
+
92
+ ### Schema Versioning
93
+
94
+ DocRouter maintains schema versions automatically:
95
+
96
+ - When you update a schema, a new version is created
97
+ - Existing prompts continue to reference their original schema version
98
+ - You can manually update prompts to use newer schema versions
99
+ - The `schema_revid` uniquely identifies each schema version
100
+
101
+ **Example Flow:**
102
+ 1. Create a schema: "Invoice Extraction" (version 1)
103
+ 2. Create a prompt linked to this schema
104
+ 3. Update the schema to add new fields (version 2 created)
105
+ 4. The prompt still uses version 1 until manually updated
106
+ 5. Edit the prompt and it automatically uses version 2
107
+
108
+ ---
109
+
110
+ ## Selecting Language Models
111
+
112
+ ### Available Models
113
+
114
+ DocRouter supports multiple AI providers through LiteLLM, including:
115
+
116
+ - **OpenAI** - GPT-4, GPT-4o models
117
+ - **Anthropic** - Claude 3.5, Claude 4 Sonnet and Opus models
118
+ - **Google Gemini** - Gemini 2.0 and 2.5 Flash and Pro models
119
+ - **Groq** - DeepSeek and Llama models with ultra-fast inference
120
+ - **Mistral** - Mistral models
121
+ - **xAI** - Grok models
122
+ - **AWS Bedrock** - Claude models via AWS infrastructure
123
+ - **Azure OpenAI / Azure AI Studio** - Available when configured
124
+ - **Google Vertex AI** - Gemini models via Google Cloud
125
+
126
+ **For the complete and up-to-date list of supported models**, see `packages/analytiq_data/llm/providers.py` in the codebase. This file defines all available LLM providers and their specific model identifiers.
127
+
128
+ ### Default Model
129
+
130
+ If no model is specified, DocRouter uses **`gpt-4o-mini`** as the default model.
131
+
132
+ ### How to Choose a Model
133
+
134
+ When creating or editing a prompt, select a model from the dropdown. Consider:
135
+
136
+ **For general document extraction:**
137
+ - **`gpt-4o-mini`** (default) - Fast, cost-effective, and reliable for most use cases
138
+ - **`gemini/gemini-2.0-flash`** - Excellent option for extraction tasks with great speed/cost ratio
139
+
140
+ **For complex or challenging documents:**
141
+ - Use higher-capability models like Claude Sonnet 4 or GPT-5 for documents requiring advanced reasoning
142
+
143
+ **For chain-of-thought applications:**
144
+ - **Grok models** are particularly well-suited for applications requiring step-by-step reasoning and chain-of-thought processing
145
+
146
+ **For high-volume processing:**
147
+ - Gemini Flash models offer excellent speed and cost efficiency
148
+ - Groq models provide ultra-fast inference for time-sensitive applications
149
+
150
+ ### Model Configuration
151
+
152
+ AI model providers must be configured in your organization settings:
153
+
154
+ 1. Navigate to Organization Settings → LLM Providers
155
+ 2. Add API keys for the providers you want to use
156
+ 3. Enable/disable specific models
157
+ 4. Only enabled models appear in the prompt editor
158
+
159
+ ---
160
+
161
+ ## Tagging and Organization
162
+
163
+ ### What are Tags?
164
+
165
+ Tags are labels that help organize and route documents to the appropriate prompts. They enable:
166
+
167
+ - **Automatic processing**: Documents with matching tags trigger specific prompts
168
+ - **Organization**: Group related prompts and documents
169
+ - **Workflow automation**: Route documents based on type or category
170
+
171
+ ### How Tags Work
172
+
173
+ 1. **Create tags** in your organization (e.g., "invoice", "receipt", "contract")
174
+ 2. **Assign tags to prompts** - Select one or more tags when creating a prompt
175
+ 3. **Upload documents with tags** - Tag documents during upload or later
176
+ 4. **Automatic execution** - When a document is uploaded with a tag, all prompts with that tag are automatically executed
177
+
178
+ ### Tag-Based Routing Example
179
+
180
+ ```
181
+ Tag: "invoice"
182
+ ├── Prompt: "Invoice Data Extraction" (runs automatically)
183
+ ├── Prompt: "Invoice Validation" (runs automatically)
184
+ └── Prompt: "Vendor Analysis" (runs automatically)
185
+
186
+ Tag: "receipt"
187
+ ├── Prompt: "Receipt OCR Enhancement"
188
+ └── Prompt: "Expense Categorization"
189
+ ```
190
+
191
+ ### Multiple Tags
192
+
193
+ Prompts can have multiple tags:
194
+
195
+ - A document with tags ["invoice", "urgent"] will trigger:
196
+ - All prompts tagged "invoice"
197
+ - All prompts tagged "urgent"
198
+ - All prompts tagged both "invoice" AND "urgent"
199
+
200
+ ---
201
+
202
+ ## Best Practices
203
+
204
+ ### 1. Write Clear, Specific Prompts
205
+
206
+ **Good:**
207
+ ```
208
+ Extract all line items from this invoice. For each line item, capture:
209
+ - Item description or product name
210
+ - Quantity (numeric value only)
211
+ - Unit price (include currency symbol)
212
+ - Line total
213
+
214
+ Format: Return as a JSON array matching the schema.
215
+ ```
216
+
217
+ **Avoid:**
218
+ ```
219
+ Get the items from the invoice.
220
+ ```
221
+
222
+ ### 2. Reference the Schema in Your Prompt
223
+
224
+ When using a schema, mention it in your prompt:
225
+
226
+ ```
227
+ Extract invoice data according to the provided schema.
228
+
229
+ Focus on accuracy for:
230
+ - invoice_number: Must be exact
231
+ - invoice_date: Use YYYY-MM-DD format
232
+ - line_items: Include all items, even if partially visible
233
+ - total_amount: Include currency symbol
234
+
235
+ Return empty strings for fields not found in the document.
236
+ ```
237
+
238
+ ### 3. Choose the Right Model for the Task
239
+
240
+ - **Complex documents**: Use Claude 3.5 Sonnet or GPT-4 Turbo
241
+ - **High volume**: Use Gemini 2.0 Flash for speed
242
+ - **Budget-conscious**: Use Claude 3 Haiku or Gemini Flash
243
+ - **Consistency needed**: Test multiple models and pick the best performer
244
+
245
+ ### 4. Use Tags Strategically
246
+
247
+ - Create tags that represent document types: "invoice", "receipt", "po", "contract"
248
+ - Use tags for workflow stages: "pending", "reviewed", "approved"
249
+ - Combine tags for conditional processing: ["invoice", "international"]
250
+
251
+ ### 5. Test and Iterate
252
+
253
+ - Start with a simple prompt and test on sample documents
254
+ - Review extraction results and refine the prompt
255
+ - Add specific instructions for edge cases
256
+ - Update the schema if you discover new fields to extract
257
+
258
+ ### 6. Version Control
259
+
260
+ - Update prompt names to indicate major changes: "Invoice Extraction v2"
261
+ - Document what changed in prompt content
262
+ - Test new versions before replacing production prompts
263
+ - Keep old prompt versions for comparison
264
+
265
+ ---
266
+
267
+ ## API Integration
268
+
269
+ DocRouter provides multiple ways to interact with prompts programmatically:
270
+
271
+ - **TypeScript/JavaScript SDK** - Type-safe client library for Node.js and browsers (see `packages/typescript/docrouter-sdk/`)
272
+ - **Python SDK** - Type-safe Python client library (see `packages/docrouter_sdk/`)
273
+ - **REST API** - Direct HTTP requests (see API documentation for endpoints)
274
+ - **MCP (Model Context Protocol)** - Integration with AI assistants like Claude Code
275
+
276
+ All methods support the same prompt operations: create, list, retrieve, update, and delete prompts.
277
+
278
+ ---
279
+
280
+ ## Examples
281
+
282
+ ### Example 1: Simple Invoice Extraction
283
+
284
+ **Prompt Name:** Invoice Basic Info
285
+
286
+ **Content:**
287
+ ```
288
+ Extract the following information from this invoice:
289
+
290
+ 1. Invoice number
291
+ 2. Invoice date
292
+ 3. Vendor/supplier name
293
+ 4. Customer/buyer name
294
+ 5. Total amount due
295
+
296
+ If any information is not found, return an empty string for that field.
297
+ ```
298
+
299
+ **Schema:** None (unstructured extraction)
300
+
301
+ **Model:** `gpt-4o-mini` (default)
302
+
303
+ **Tags:** ["invoice"]
304
+
305
+ ---
306
+
307
+ ### Example 2: Structured Receipt Processing
308
+
309
+ **Prompt Name:** Receipt Data Extraction
310
+
311
+ **Content:**
312
+ ```
313
+ You are processing a receipt document. Extract all transaction details with high accuracy.
314
+
315
+ Required fields:
316
+ - Merchant name and address
317
+ - Transaction date and time
318
+ - All purchased items with prices
319
+ - Subtotal, tax breakdown, and total
320
+ - Payment method
321
+
322
+ Return the data in strict adherence to the provided JSON schema. Use empty strings for missing data.
323
+ ```
324
+
325
+ **Schema:** "Receipt Schema" (structured output with line items array)
326
+
327
+ **Model:** Default (`gpt-4o-mini`) or higher-capability model for complex documents
328
+
329
+ **Tags:** ["receipt", "expense"]
330
+
331
+ ---
332
+
333
+ ### Example 3: Contract Analysis
334
+
335
+ **Prompt Name:** Contract Key Terms
336
+
337
+ **Content:**
338
+ ```
339
+ Analyze this contract and extract key terms and conditions.
340
+
341
+ Focus on:
342
+ - Party names (all parties involved)
343
+ - Contract effective date and expiration date
344
+ - Contract value or payment terms
345
+ - Key obligations of each party
346
+ - Termination clauses
347
+ - Jurisdiction and governing law
348
+
349
+ For each extracted element, note the page number where found.
350
+ Summarize any unusual or non-standard clauses.
351
+ ```
352
+
353
+ **Schema:** "Contract Schema" (complex nested structure)
354
+
355
+ **Model:** Higher-capability model (e.g., Claude Sonnet 4) recommended for complex reasoning
356
+
357
+ **Tags:** ["contract", "legal"]
358
+
359
+ ---
360
+
361
+ ### Example 4: Resume Parsing
362
+
363
+ **Prompt Name:** Resume Information Extraction
364
+
365
+ **Content:**
366
+ ```
367
+ Extract candidate information from this resume/CV.
368
+
369
+ Personal Information:
370
+ - Full name
371
+ - Email address
372
+ - Phone number
373
+ - Location (city/country)
374
+
375
+ Professional Summary:
376
+ - Current or most recent position
377
+ - Years of experience
378
+ - Key skills (programming languages, tools, frameworks)
379
+
380
+ Education:
381
+ - Degrees earned
382
+ - Institutions attended
383
+ - Graduation years
384
+
385
+ Work Experience:
386
+ - Company names
387
+ - Job titles
388
+ - Employment dates
389
+ - Key responsibilities
390
+
391
+ Format all data according to the provided schema. Use empty strings where information is not available.
392
+ ```
393
+
394
+ **Schema:** "Resume Schema"
395
+
396
+ **Model:** `gemini/gemini-2.0-flash` or default (`gpt-4o-mini`)
397
+
398
+ **Tags:** ["resume", "hr", "candidate"]
399
+
400
+ ---
401
+
402
+ ## Prompt Workflow
403
+
404
+ ### 1. Design Phase
405
+ - Identify what data needs to be extracted
406
+ - Determine if a schema is needed for structured output
407
+ - Choose the appropriate AI model based on complexity
408
+ - Plan which tags should trigger this prompt
409
+
410
+ ### 2. Creation Phase
411
+ - Write clear, specific prompt instructions
412
+ - Associate with a schema if structured output is needed
413
+ - Select the AI model
414
+ - Add relevant tags for automatic processing
415
+
416
+ ### 3. Testing Phase
417
+ - Upload sample documents with appropriate tags
418
+ - Review extraction results
419
+ - Refine prompt wording and instructions
420
+ - Adjust schema if fields are missing or incorrect
421
+
422
+ ### 4. Production Phase
423
+ - Tag incoming documents to trigger prompt execution
424
+ - Monitor extraction quality and accuracy
425
+ - Update prompts as document formats evolve
426
+ - Version prompts when making significant changes
427
+
428
+ ---
429
+
430
+ ## Troubleshooting
431
+
432
+ ### Common Issues
433
+
434
+ **Issue:** LLM returns empty or incorrect data
435
+ - **Solution:** Make prompt more specific, provide examples, or use a more capable model
436
+
437
+ **Issue:** Output doesn't match schema
438
+ - **Solution:** Verify strict mode is enabled, mention schema in prompt content
439
+
440
+ **Issue:** Prompt not triggered automatically
441
+ - **Solution:** Check that document tags match prompt tags exactly
442
+
443
+ **Issue:** Slow extraction performance
444
+ - **Solution:** Switch to a faster model like `gemini/gemini-2.0-flash`
445
+
446
+ **Issue:** Inconsistent results across documents
447
+ - **Solution:** Add more specific instructions, provide format examples and counter-examples, or switch to a higher-capability models
448
+
449
+ ---
450
+
451
+ ## Version Control
452
+
453
+ DocRouter maintains prompt versioning:
454
+
455
+ - Each prompt update creates a new version
456
+ - `prompt_version` increments with each change
457
+ - `prompt_revid` uniquely identifies each version
458
+ - Previous versions remain accessible for historical processing
459
+
460
+ ---
461
+
462
+ ## References
463
+
464
+ - [Schema Definition Manual](./schemas.md)
465
+ - [LiteLLM Documentation](https://docs.litellm.ai/)
466
+ - [DocRouter API Documentation](../README.md)
467
+
468
+ ---
469
+
470
+ **Document Version:** 1.0
471
+ **Last Updated:** 2025-01-11
472
+ **Maintained by:** DocRouter Development Team