Context
An enterprise communication analytics platform, built at Computech and run on Azure against Computech’s own Microsoft 365 tenant. It measures how people work across email, Teams messages, calls, meetings and presence: response times, meeting attendance, availability and a weighted performance score. Managers and HR read it on a React dashboard, and a LangGraph agent explains the numbers in words.
It is an employee-analytics tool, so privacy was a design input from the start: metadata only, role-based access, audit logging and retention limits, each specified in the project’s component specs.
The problem
Asking an LLM to “analyse team performance” invites it to compute numbers it cannot be held to and to read content it should never see. Two things had to be true. Every figure on the screen must come from code that gives the same answer twice. And the model must never see a message body.
Design
The rule the whole system follows: the LLM never computes a metric.
- Ingestion. Microsoft Graph delta queries and change-notification webhooks feed an event normalizer. The normalizer keeps metadata and rejects content fields before anything reaches PostgreSQL.
- Metrics engine. SQL and Python compute nightly and incremental rollups. The performance score is a weighted formula whose weights HR admins own through the API. It is never an LLM opinion.
- Agent. The agent never calls Microsoft Graph or the database. Its tools are thin, typed calls to the REST API, and each call carries the asking user’s identity so the API applies that user’s visibility. A 403 raises an error and is never swallowed.
- Determinism before the model. For summaries, anomaly questions and the SLA outlook, the graph decides which tools to call. A
gathernode fans out a fixed set of calls, computes deltas itself and runs a pure Python anomaly detector. Then exactly one LLM node writes the explanation. Only the free-form question path lets the model choose tools, through a capped ReAct loop, and its output passes the same checks. - Pluggable model.
init_chat_modelselects Anthropic or Azure OpenAI from configuration. Production runs on Azure OpenAI.
Guardrails
- A numeric firewall. The LLM node must return a fixed
InsightResponseschema through structured output. After generation, a validator walks every number in that output and checks it against the data the tools returned, within a tight rounding tolerance. A draft with an invented or miscopied number goes back to the model once, with the violations listed. If it fails again, the user gets the metrics without the narrative. - Content never enters the system. The normalizer drops content fields, and a CI guard checks that no content field creeps back in.
- A metric allow-list. The trend tool only accepts metric names from a fixed set, so a name taken from a user’s question cannot become an arbitrary query parameter. A drift test keeps that list matched to the metrics the engine emits.
- Name resolution without the model. An unknown name stops the run, and an ambiguous one returns the candidate list. Neither reaches the LLM.
- Rollout requirements. Before use beyond Computech’s own tenant, the specs require written HR and management approval, a published employee notice, passing tenant verification checks, and green RBAC and privacy guards.
Evals and results
- Golden validation gate. It seeds a tiny fixed tenant, runs the real engine over pinned dates, and checks every headline number against a value computed by hand in the test. It targets the semantic bugs unit tests had passed over, and it runs in under a second. When I added it, it found no new discrepancy, which was the first systematic evidence that the recent metric fixes held end to end.
- Test suites in CI. At the August 2026 count there were 811 backend tests (22 of them golden), 75 agent tests and 419 frontend tests. GitHub Actions runs them on every push and pull request, alongside a typecheck and a secret scan.
- Validator tests. The agent suite covers the numeric firewall, the metric allow-list, the anomaly detector and the SLA forecast narration.
What is not measured: there is no scored eval of the agent’s prose, such as how well an explanation helps a manager. The validator checks the numbers. Whether an explanation is useful is not checked.
A failure I handled
After deployment, availability figures on the dashboard were wrong in ways a manager would notice: some people read close to 0%, and someone who was online got credit for hours that had not happened yet. I audited every metric computation and found three defects in one pair of presence functions:
- An open presence interval was clipped to the end of the period, not to now, so a person currently Available got the rest of the month counted as online time.
- The availability denominator was the whole period’s business hours, including the time before presence recording started. “No data” read as “0% available”, breaking the system’s own rule that missing data is absent, not zero.
- Out of Office and unknown presence stayed in the denominator, so a week of approved leave scored 0%.
The fix clips at now, makes the denominator the recorded coverage of tracked states only, removes excluded states from both sides, and returns no value when nothing was recorded. New registry tests pin each case: an open interval clipped at now, a pre-recording period that reads as absent, a leave week that does not zero availability, and known-answer percentages. The audit also showed zero tests on the registry metrics, the rollup engine and score persistence, which is where these defects lived. I added those tests in the same wave, and the golden gate came after.
Stack
Python, FastAPI, LangGraph, LangChain init_chat_model, Pydantic, PostgreSQL, Celery and Redis, Microsoft Graph, React, TypeScript and Tailwind, MSAL and Entra ID SSO, Docker, Azure OpenAI.
Links
Private repository, proprietary to Computech.