The Prompt Enhancement System transforms simple agent prompts (e.g., "Search for Nova") into detailed, comprehensive extraction prompts using admin-configured templates and contextual enrichment.
This system enables:
┌─────────────────┐ │ Agent Request │ "Search for Nova" └────────┬────────┘ │ ▼ ┌─────────────────────────────────────────┐ │ PromptEnhancementService │ │ 1. Parse agent intent │ │ 2. Load admin template from database │ │ 3. Add workspace context │ │ 4. Build enhanced prompt │ └────────┬────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────┐ │ Enhanced Prompt │ │ "Analyze this PDF catalog and │ │ identify ALL products... │ │ SPECIAL: Focus on finding 'Nova'... │ │ [Full detailed instructions]" │ └────────┬────────────────────────────────┘ │ ▼ ┌─────────────────┐ │ Claude/GPT AI │ Processes with full context └─────────────────┘
Agent requests are intentionally simple, such as:
The PromptEnhancementService enhances the prompt by:
Parsing Intent: Understands what the agent wants
Loading Admin Template: Retrieves custom prompt from database
discoveryproductsAdding Context: Enriches with workspace settings
Building Final Prompt: Combines everything
Claude/GPT receives the full, detailed prompt and returns comprehensive results.
Table: prompts (Unified table for all AI prompts)
The table stores the following fields: id, workspace_id, prompt_type (e.g., 'extraction', 'agent'), stage (e.g., 'discovery', 'chunking', 'image_analysis', 'entity_creation'), category (e.g., 'products', 'certificates', 'logos', 'specifications'), name, prompt_text (the actual prompt template), system_prompt (optional), description, quality_threshold (default 0.7), is_active (default true), is_custom (default false), version (default 1), created_at, updated_at, created_by, and updated_by.
Default prompts are seeded using a seed script located at cd mivaa-pdf-extractor then running python scripts/seed_default_prompts.py.
Default Prompts Include:
discovery/products - Comprehensive product extractiondiscovery/certificates - Certificate and compliance discoverydiscovery/logos - Logo and brand mark identificationdiscovery/specifications - Technical specification extractionVia Admin API:
The admin API provides endpoints to get the current prompt for a given stage and category, update a prompt with a new template, quality threshold, and description, and view the version history for a prompt.
Via Admin Panel:
Step 1: Parse Intent — The system identifies the action as "search", the target as "NOVA", the category as "products", and the specificity as "high".
Step 2: Load Admin Template — The full admin template is retrieved from the database, containing detailed instructions for analyzing the PDF catalog and identifying all products with complete metadata.
Step 3: Add Context — Workspace settings such as quality threshold and preferred models are combined with document context such as total page count and PDF preview text.
Step 4: Build Enhanced Prompt — The final prompt combines the user request, the full admin template instructions, special handling directives to prioritize finding the named product, the required JSON output format, and the PDF content.
Send a multipart form upload to POST /api/rag/documents/upload including the PDF file, categories (e.g., "products"), agent_prompt (e.g., "search for NOVA"), enable_prompt_enhancement set to true, and workspace_id.
The response includes a job_id, document_id, processing status, a status URL for polling, the categories being extracted, the discovery model being used, and a flag confirming prompt enhancement is enabled.
✅ Full Control: Customize extraction prompts without code changes ✅ Version History: Track all prompt changes with audit trail ✅ Quality Tuning: Adjust quality thresholds per category ✅ Testing: Test prompts before deploying to production
✅ Simplicity: Send simple requests like "search for Nova" ✅ Consistency: Always get high-quality, detailed results ✅ Flexibility: No need to know extraction details
✅ Maintainability: Update prompts without code deployment ✅ Scalability: Easy to add new categories and stages ✅ Quality: Consistent extraction across all documents ✅ Auditability: Full history of prompt changes
The following enhancements are planned for future releases: