The SOW Analyzer is a Microsoft Teams-integrated AI validation system that evaluates uploaded Statements of Work (SOWs) against predefined “golden” template documents.
Architecture Components:
The system supports:
Uploaded documents are processed in-memory and are not persisted.
Teams User ↓ Teams Bot (teams_bot.py) ↓ File Download + Validation ↓ POST /analyze-sow (app.py) ↓ Azure Document Intelligence (layout extraction) ↓ Azure OpenAI GPT comparison ↓ Structured Response to Teams
Entry point:
async def on_turn(turn_context: TurnContext)
Behavior:
Defined in:
SUPPORTED_FILE_TYPES = { ".pdf": "application/pdf", ".doc": "application/msword", ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", }
Extension gating:
if not any(filename.lower().endswith(ext) for ext in SUPPORTED_FILE_TYPES.keys()):
Function:
def _validate_file_signature(filename: str, data: bytes)
Validation Rules:
Purpose:
Function:
async def _download_bytes(url: str, filename: str) -> bytes
Security controls:
Function:
async def _post_to_analyzer(filename: str, file_bytes: bytes, content_type: str)
Behavior:
@app.post("/analyze-sow") async def analyze_sow(file: UploadFile = File(...))
Validation:
Allowed MIME types:
if filename.endswith(".docx"): content_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" elif filename.endswith(".doc"): content_type = "application/msword" else: content_type = "application/pdf"
Purpose:
def extract_layout_text(file_bytes: bytes, content_type: str) -> str
Uses:
Call Pattern:
poller = client.begin_analyze_document( "prebuilt-layout", document=file_bytes, content_type=content_type )
Output:
compare_against_best_template( uploaded_sow_text, golden_templates )
Purpose:
Characteristics:
Golden templates are loaded at application startup and held in memory.
Design Principles:
Uploaded files:
Processing is memory-bound only.
Controls implemented:
Service separation:
Benefits:
Required Environment Variables:
Timeouts:
File Size Limit:
Error Categories:
Errors are intentionally explicit to simplify debugging in production.
Potential enhancements:
Performance Factors:
Scalability:
The SOW Analyzer is a stateless, AI-driven SOW validation engine embedded directly in Microsoft Teams. It combines structured document extraction and semantic reasoning while maintaining strong governance controls and zero persistent storage of uploaded contractual documents.
It is designed for: