Table of Contents

SOW Analyzer – Technical User Guide & Reference Manual

1. System Overview

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.


2. High-Level Architecture Flow

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

3. Teams Bot (teams_bot.py)

3.1 Message Handling

Entry point:

async def on_turn(turn_context: TurnContext)

Behavior:


3.2 Supported File Types

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()):

3.3 File Signature Validation

Function:

def _validate_file_signature(filename: str, data: bytes)

Validation Rules:

Purpose:


3.4 Download Logic

Function:

async def _download_bytes(url: str, filename: str) -> bytes

Security controls:


3.5 Analyzer POST Logic

Function:

async def _post_to_analyzer(filename: str, file_bytes: bytes, content_type: str)

Behavior:


4. Backend API (app.py)

4.1 Endpoint Definition

@app.post("/analyze-sow")
async def analyze_sow(file: UploadFile = File(...))

Validation:

Allowed MIME types:


4.2 Content-Type Mapping Logic

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:


5. Document Extraction (layout_client.py)

5.1 Extraction Function

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:


6. GPT Comparison Engine

6.1 Function

compare_against_best_template(
    uploaded_sow_text,
    golden_templates
)

Purpose:

Characteristics:


7. Golden Template Management

Golden templates are loaded at application startup and held in memory.

Design Principles:


8. Security Architecture

8.1 No Persistent Storage

Uploaded files:

Processing is memory-bound only.


8.2 Input Hardening

Controls implemented:


8.3 AI Isolation

Service separation:

Benefits:


9. Configuration Reference

Required Environment Variables:

Timeouts:

File Size Limit:


10. Error Handling Behavior

Error Categories:

Errors are intentionally explicit to simplify debugging in production.


11. Extension Points

Potential enhancements:


12. Operational Characteristics

Performance Factors:

Scalability:


13. Compliance Considerations


14. Summary

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: