This document describes the template identification functionality added to the Legal Document Organizer. The system now automatically identifies template documents during metadata extraction and handles them appropriately.
Added template_analysis object to DocumentMetadata interface:
template_analysis?: {
is_template: boolean;
confidence: 'HIGH' | 'MEDIUM' | 'LOW';
indicators: string[];
template_type?: string;
field_placeholders?: string[];
typical_use_case?: string;
}- Integrated template identification as STEP 1 of metadata extraction
- Uses criteria from the Template Identification System Prompt
- Identifies templates based on:
- Primary indicators: [BLANK], [FORM], (Form), Template in filename
- Secondary indicators: Generic names, placeholder fields
- Exclusion criteria: EXECUTED, specific party names, filled dates
- When
is_templateis true, status is automatically set to "template" - Ensures consistency between template analysis and document status
- Templates with [BLANK], [FORM], etc. are routed to 09_Templates folder
- Subfolder selection based on template type (By_Category or By_Department)
- Added new intent:
REQUEST_TEMPLATE - Recognizes phrases like:
- "I need a template for..."
- "Show me templates"
- "Get me a blank [document type]"
- Template search automatically filters for status: "template"
- Discord bot help now includes template request examples
- Clear guidance on how to request templates
- File is uploaded or detected
- Metadata extraction begins with template identification
- If template indicators found →
is_template: true - Status automatically set to "template"
- Document classified to 09_Templates folder
- Template metadata saved including placeholders and use case
- User requests a template (e.g., "I need an employment agreement template")
- Bot recognizes REQUEST_TEMPLATE intent
- Searches for documents with status: "template" and matching type
- Returns templates with descriptions and confidence levels
Two test scripts were created:
test-template-prompt.ts- Tests the template identification prompt with sample contenttest-template-identification.ts- Tests end-to-end with actual files
Run tests with:
npx ts-node test-template-prompt.ts
npx ts-node test-template-identification.ts- ✅
Employment Agreement [BLANK].docx→ Template (HIGH confidence) - ✅
SAFE Agreement (Form).pdf→ Template (HIGH confidence) - ❌
Board Consent EXECUTED.pdf→ Not a template - ❌
Agreement - John Smith.pdf→ Not a template (specific party name)
- "Show me all templates"
- "I need an employment agreement template"
- "Find SAFE agreement template"
- "Get me a blank NDA"
- Template Versioning: Track template versions and updates
- Template Categories: More granular categorization within templates
- Usage Tracking: Monitor which templates are most requested
- Template Filling: Help users fill out templates with required information
- Template Recommendations: Suggest templates based on user needs
No additional configuration required. The system uses existing API keys:
- OpenAI API key for classification and metadata extraction
- Gemini API key (optional) for enhanced PDF processing
Template identification is automatic and requires no user intervention.