Automated document validation system that enforces the Mace Control Centre Writing Style Guide using Azure Functions, Claude AI, and SharePoint integration.
Governance-verified. Tested and compliant against SOC 2, ISO 27001, and GDPR using the Microsoft Agent Governance Toolkit v2.1.0. Access controls, structured audit logging, prompt injection detection, and policy enforcement built in.
- Automatic Validation - Documents validated on upload to SharePoint
- AI-Powered - Claude Haiku 4.5 for intelligent language corrections
- British English - Comprehensive British spelling enforcement (25+ rules)
- Grammar Rules - Contraction expansion, punctuation, symbol replacement
- Auto-Fix - Most issues corrected automatically
- Multi-Format - Word, Visio, Excel, and PowerPoint support
- Beautiful Reports - Professional HTML reports with colour-coded results
- Audit Trail - Structured JSON audit events to Application Insights + SharePoint validation history
- Fast - Typical validation in 5-15 seconds
- Secure - API key + Azure AD access control, encrypted secrets, prompt injection detection
- Scalable - Serverless architecture, auto-scaling
- Governed - Tested and compliant (SOC 2, ISO 27001, GDPR) via Microsoft Agent Governance Toolkit v2.1.0
- finalized, color, center, analyze
+ finalised, colour, centre, analyseAnd 20+ more British spellings!
- can't, don't, won't, isn't
+ cannot, do not, will not, is not- M&S partnership - 50% growth
+ M and S partnership - 50 percent growth- Budget: 1000 for 5000 items
+ Budget: 1,000 for 5,000 items- Mixed fonts (Calibri, Times New Roman, etc.)
+ All text standardized to Arial---
title: MaceStyle System Architecture
---
graph LR
SP[SharePoint]:::primary -->|Triggers| LA[Logic App]:::primary
LA -->|Sends document| AF[Azure Function]:::primary
AF -->|Authenticates via| AD[Azure AD]:::primary
AF -->|Validates text| AI[Claude AI]:::primary
AF -->|Reads & writes| GR[Graph API]:::primary
GR -->|Updates| SP
classDef primary fill:#c5d9f1,stroke:#1F4E79,color:#0a2744
classDef decision fill:#fac775,stroke:#854f0b,color:#412402
classDef outcome fill:#9fe1cb,stroke:#0f6e56,color:#04342c
Components:
- SharePoint Online - Document storage & triggers
- Power Automate - Workflow orchestration
- Azure Functions - Serverless validation logic (Python 3.11)
- Claude AI - Advanced language processing
- Microsoft Graph API - SharePoint integration
- Azure AD - Secure authentication
Detailed Architecture Documentation
- Azure subscription (Owner/Contributor access)
- Microsoft 365 with SharePoint Online
- Power Platform admin access
- Anthropic API key (Get one here)
- Python 3.11+
- Azure Functions Core Tools v4
-
Clone the repository
git clone https://github.com/stephencummins/MaceStyle.git cd MaceStyle -
Set up Azure resources
- Create Azure Function App
- Create App Registration in Azure AD
- Configure API permissions (
Sites.Selected-- see Security below)
-
Configure SharePoint
- Create site:
/sites/StyleValidation - Create lists:
Style Rules,Validation Results - Add custom columns to Document Library
- Create site:
-
Deploy Azure Function
cd MaceStyleValidator # Install dependencies pip install -r requirements.txt # Deploy to Azure func azure functionapp publish <your-function-app-name>
-
Configure environment variables
SHAREPOINT_TENANT_ID="your-tenant-id" SHAREPOINT_CLIENT_ID="your-client-id" SHAREPOINT_CLIENT_SECRET="your-secret" SHAREPOINT_SITE_URL="https://tenant.sharepoint.com/sites/StyleValidation" ANTHROPIC_API_KEY="sk-ant-..."
-
Populate style rules
python3 populate_style_rules.py
-
Create Power Automate flow
- Trigger: When file created/modified in SharePoint
- Action: HTTP POST to Azure Function
- Action: Parse JSON response
- Upload document to SharePoint library
- Wait for validation (~10 seconds)
- Check results:
- Status badge: Passed / Failed
- Click Validation Report link for details
- Download corrected file (if fixes applied)
Manage validation rules:
- Go to Style Rules list in SharePoint
- Add/edit rules:
- Set
UseAI: Yesfor Claude AI validation - Set
AutoFix: Yesfor automatic corrections - Adjust
Priorityfor execution order
- Set
Monitor validations:
- Azure Portal > Function App > Application Insights
- SharePoint > Validation Results list
- Review HTML reports for trends
Style Validation Report
[PASSED Badge]
Document: Project_Report.docx
Validated: 08 November 2025 at 20:42:15 UTC
Summary
Issues Found: 156 | Auto-Fixed: 156 | Remaining Issues: 0
Fixes Applied (156)
Fixed 145 text runs to Arial
Applied 8 style corrections (British English, contractions)
Replaced 'finalized' with 'finalised' (3 instances)
Issues Detected (156)
Found 145 text runs with incorrect font
Found 8 style violationsA comprehensive test document is included:
# Create test document with 40+ violations
python3 create_test_document.py
# Upload to SharePoint
# test_files/test_validation_comprehensive.docxTest document includes:
- British English spelling errors
- Contractions
- Symbol violations (& and %)
- Number formatting issues
- Font inconsistencies
| Document | Description |
|---|---|
| Technical Architecture | System design, components, data flow |
| User Guide | How to use the validator |
| Configuration & Setup | Complete installation guide |
| Visio Validation Guide | Comprehensive Visio validation documentation |
| Visio Structural Rules Examples | Ready-to-use SharePoint rules for layout validation |
MaceStyle has been verified against the Microsoft Agent Governance Toolkit v2.1.0 across six assessment categories. All frameworks pass.
| Framework | Status | Controls |
|---|---|---|
| SOC 2 | Compliant | CC6.1 Access Controls, CC7.2 System Monitoring |
| ISO 27001 | Compliant | Information security management |
| GDPR | Compliant | No PII processed, data minimisation confirmed |
| Check | Result |
|---|---|
| Credential exposure scan | Clean - no hardcoded secrets, all from env vars |
| Security controls (10 checks) | 10/10 passed - file type validation, error handling, MSAL auth, Claude response parsing, path traversal prevention, max_tokens limit, temperature control |
| Prompt injection resilience | 6/6 payloads detected - including 2 at HIGH threat level |
| Policy engine (adversarial actions) | 3/3 blocked - system file read, DROP TABLE, credential exposure |
| Governance alignment | Aligned - no violations, severity 0.0 |
| Privacy analysis | No PII - risk score 0.0 |
The governance check is rerunnable and produces a full markdown report:
cd MaceStyleValidator
source ../.venv/bin/activate # Requires agent-governance-toolkit v2.1.0
python3 ../governance_check.py
# Output: governance_report.mdEvery request is validated before processing via access_control.py:
- API key mode (default) - validates
X-Api-KeyorAuthorization: Bearerheader - Azure AD mode - validates
X-MS-CLIENT-PRINCIPALwith app ID allowlisting - Caller identity extraction - IP, user agent, Azure AD claims, Power Automate run IDs logged to audit trail
Every validation emits a structured JSON audit event to Application Insights via monitoring.py:
- Request correlation ID, caller identity, document details
- Per-phase timing (auth, rule fetch, download, validation, upload)
- Claude API token usage and estimated cost
- Issues found, fixes applied, report upload status
- Health check endpoint:
GET /api/HealthCheck(returns200healthy /503unhealthy) - Alert emission with severity levels (INFO, WARNING, CRITICAL)
Instead of granting tenant-wide access to all SharePoint sites, MaceStyle uses Sites.Selected -- a permission that grants no access by default. Access is then explicitly granted to only the target site via the Graph API.
- In Entra ID, grant the app
Sites.Selected(Application permission) and admin-consent it - Run the included helper script to grant access to the specific site:
python3 grant_site_permissions.pyThis calls the Graph API to grant read/write access on the target site only. See docs/azure-admin-setup.md for full details.
- Site-scoped permissions - Uses
Sites.Selected(not tenant-wideSites.ReadWrite.All) - Access control - API key or Azure AD authentication on every request
- Azure AD (MSAL) - Secure service principal for Graph API
- Encrypted secrets - Azure Key Vault / App Settings
- Minimal permissions - Principle of least privilege
- Prompt injection detection - Adversarial payloads caught before reaching Claude
- Structured audit trail - JSON events to Application Insights + SharePoint
- No data persistence - Documents processed in-memory
Estimated monthly costs (for 1,000 documents):
| Service | Cost |
|---|---|
| Azure Functions (Consumption) | $5-10 |
| Application Insights | $2-5 |
| Claude AI (Haiku) | ~$10 |
| SharePoint | Included in M365 |
| Total | ~$17-25/month |
For 100 documents/month: ~$2-5/month
- Backend: Python 3.11, Azure Functions v4
- AI: Claude Haiku 4.5 (Anthropic)
- Integration: Microsoft Graph API, MSAL
- Document Processing: python-docx, python-pptx, openpyxl, vsdx
- Workflow: Power Automate
- Storage: SharePoint Online
- Auth: Azure AD (Entra ID) + API key access control
- Governance: Microsoft Agent Governance Toolkit v2.1.0
- Monitoring: Application Insights + structured JSON audit events
- Average processing time: 5-15 seconds
- Concurrent validations: Auto-scaling (Azure Functions)
- Supported file size: Up to 100 pages recommended
- API rate limits: Graph API throttling handled
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Very large files (>100 pages) may timeout
- Complex table validation limited
- Visio font detection uses numeric IDs (font 0 = Arial)
See Issues for full list.
- Enhanced Visio diagram validation (font, colour, text style, structure)
- Visio structural validation (shape size, position, page dimensions)
- Excel spreadsheet validation with write-back
- PowerPoint validation with text run corrections
- SOC 2 / ISO 27001 / GDPR compliance (AGT v2.1.0)
- Structured audit logging and health check endpoint
- Access control (API key + Azure AD)
- Prompt injection detection
- PDF document support
- Multi-language support
- Custom rule templates
- Batch validation API
- Real-time validation in Word Online
This project is licensed under the MIT License - see the LICENSE file for details.
- Anthropic - Claude AI API
- Microsoft - Azure Functions, SharePoint, Graph API
- python-docx - Word document manipulation
- Mace Group - Writing Style Guide
- Documentation: docs/
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Give a star if this project helped you!
Built with Azure Functions & Claude AI
Automated document validation has never been easier!