Back
Legal & Contract Analysis

Clause-Level Contract Risk Analysis, Inside Google Docs

A built and deployed sidebar add-on that scores individual Master Service Agreement clauses against jurisdiction-specific legal standards in real time, without ever leaving the document.

August 21, 2026
Share
ENGAGEMENT SNAPSHOT

CS-011_ClauseGuard image 1
Figure 1 - Key figures from this engagement, at a glance.
EXECUTIVE SUMMARY
Our client's legal and business stakeholders needed a way to assess the risk of individual clauses inside Master Service Agreements across multiple jurisdictions, without exporting documents into a separate review tool or waiting on outside counsel for a first read.
Pfactorial Technologies built and deployed ClauseGuard, a Google Docs sidebar add-on that lets a user select a clause, choose a jurisdiction, and receive a risk classification, a plain-language summary, and an actionable recommendation in real time, generated by an LLM constrained with jurisdiction-specific legal context.
The MVP ships with two fully active jurisdictions - Philippines and New York - and three additional jurisdictions visible in the interface as coming soon, on an architecture designed explicitly so a new jurisdiction is added as a self-contained module rather than a change to the core system.
Why this engagement is representative This engagement demonstrates Pfactorial's approach to applied legal AI: jurisdiction-specific reasoning encoded as modular, swappable prompt modules rather than one generic legal prompt, with every architectural choice - framework, compute, jurisdiction handling - backed by an evaluated and rejected alternative.
THE CHALLENGE
Delivering real-time, jurisdiction-aware clause risk analysis inside a live document editor surfaced four distinct design problems.

1. Legal risk depends entirely on jurisdiction

The same governing-law clause can be low risk in one jurisdiction and materially riskier in another, so the system needed a way to apply genuinely different legal context per jurisdiction rather than one generic analysis.

2. The tool had to stay inside the reviewer's existing workflow

Legal professionals and business stakeholders review MSAs directly in Google Docs; requiring an export to a separate tool would have broken the workflow the tool was meant to speed up.

3. Risk needed to be a defensible score, not just a label

A bare high/medium/low tag without a transparent basis is hard to act on - the system needed a formula-based score with its inputs shown, not an opaque classification.

4. The architecture had to support jurisdictions not yet built

With only two jurisdictions active at launch and three more already planned, the system needed a structure where adding a jurisdiction is additive, not a rearchitecture.
The real brief Not "summarize a contract with AI" but "score individual clauses against real jurisdiction-specific legal standards, inside the document the reviewer is already working in, on an architecture that scales cleanly to new jurisdictions."
THE SOLUTION
Pfactorial built ClauseGuard as a two-tier system: a Google Docs sidebar frontend and a serverless backend that routes each clause to a jurisdiction-specific prompt module before returning a structured, scored response.
CS-011_ClauseGuard image 2
Figure 1 - The request path: clause selection, jurisdiction routing to a dedicated prompt module, LLM analysis with structured output, and a color-coded risk card back in the sidebar.

Architectural principles

  • Jurisdiction as a first-class routing dimension - each jurisdiction has its own module with a tailored system prompt, legal context (Civil Code and Corporation Code for the Philippines; UCC Article 2 and common law for New York), and output format - not one shared legal prompt with a jurisdiction variable.
  • Risk is a formula, not a guess - conflict likelihood and impact are each scored 1 to 5 by the LLM, multiplied into a risk score, and classified as High, Medium, or Low - a transparent, auditable calculation rather than an unexplained label.
  • No custom model training required - the system uses prompt engineering with jurisdiction-specific system prompts to encode legal expertise into inference, rather than training or fine-tuning a custom model for an MVP-stage product.
  • New jurisdictions are additive, not disruptive - each jurisdiction is architected as a separate Python module with its own system prompt and legal context, so adding a jurisdiction does not require changes to existing ones.
CAPABILITIES DELIVERED
ClauseGuard covers the full path from selecting a clause in a live document to a scored, actionable risk assessment, without leaving Google Docs.
CAPABILITY
WHAT IT DOES
In-Document Clause Selection
A persistent sidebar lets users select a jurisdiction and highlight clause text directly inside the Google Doc they are already reviewing.
Jurisdiction-Specific Risk Analysis
Routes each request to a dedicated prompt module encoding that jurisdiction's legal context - Civil Code and Corporation Code for the Philippines, UCC Article 2 and common law for New York.
Transparent Risk Scoring
Calculates a risk score from conflict-likelihood and impact ratings, classified as High, Medium, or Low with a color-coded indicator.
Actionable Recommendations
Returns a one-sentence summary and a one-to-two-sentence recommendation alongside relevant legal topic tags for every analyzed clause.
Secure, Authenticated Requests
Authenticates every analysis request via Google ID Token validation, with service-account authentication for internal GCP service calls.
Extensible Jurisdiction Architecture
Ships with three additional jurisdictions visible in the UI as coming soon, ready to activate as self-contained modules without touching the core system.
CS-011_ClauseGuard image 3
Figure 2 - Architectural decisions evaluated and rejected during design: framework, deployment target, self-hosting, and prompt-module structure.
Design note The MVP performs clause-level analysis only, via manual text selection, with no data persistence - each session is stateless, which simplifies compliance but does not yet support cross-session comparison. Full document scanning, automated clause detection, and side-by-side multi-jurisdiction comparison are scoped for a later phase, not the current MVP.
ENGINEERING FOR SCALE AND RELIABILITY
Several engineering decisions were made on evaluated evidence rather than convenience, shaping how ClauseGuard performs and scales as a serverless legal AI tool.

FastAPI over Flask, for concurrent review load

FastAPI's async-first design was chosen over a simpler synchronous Flask implementation specifically because it provided better throughput when multiple document reviews run concurrently.

Cloud Run over Cloud Functions, for batch-friendly limits

Cloud Functions Gen 2 was rejected because its cold-start and timeout limits were too constraining for batch document analysis; Cloud Run's serverless container model scales from zero without those constraints.

Managed LLM APIs over self-hosting, on a cost basis

a self-hosted model was evaluated for data sovereignty but rejected because latency and GPU cost exceeded serverless API costs at MVP scale - a decision documented, not assumed.

Modular jurisdiction handlers over a monolithic prompt file

a single prompt file for all jurisdictions was rejected in favor of modular per-jurisdiction modules, which proved more maintainable as prompt complexity grew with each added jurisdiction.

Async processing absorbs concurrent load

requests are processed asynchronously via Cloud Tasks with retry logic for transient LLM API failures, so concurrent analysis requests do not compete for the same synchronous request cycle.

Secrets and CI/CD are managed, not manual

LLM API keys and credentials are held in Google Secret Manager, with Cloud Build automatically building, testing, and deploying container images to Artifact Registry on every change.
DELIVERY APPROACH
ClauseGuard was built and deployed as an MVP, moving from architectural evaluation through to a live, two-jurisdiction sidebar add-on.
1. Evaluate and select the core architecture - compared FastAPI against Flask and Cloud Run against Cloud Functions Gen 2 on concurrency and batch-processing grounds before committing.
2. Build the sidebar frontend - implemented the Google Docs CardService sidebar with jurisdiction selection, action buttons, and expandable result sections.
3. Build the jurisdiction-routed backend - implemented the single analysis endpoint, request validation, and per-jurisdiction prompt module routing for Philippines and New York.
4. Implement risk scoring and structured output - built the conflict-likelihood-times-impact scoring formula and the standardized JSON response consumed by the sidebar.
5. Deploy and secure the platform - containerized the backend on Cloud Run behind OAuth 2.0 authentication, with CI/CD via Cloud Build and secrets in Secret Manager.
RESULTS AND IMPACT

CS-011_ClauseGuard image 4
Figure - Key outcomes from this engagement.
In a worked comparison of the same governing-law clause across both active jurisdictions, ClauseGuard returned a risk score of 4 for the Philippines (conflict likelihood 1, impact 1 - strong alignment with local law) against a risk score of 36 clamped to the tool's High classification for New York (conflict likelihood 3, impact 3), correctly reflecting the moderate public-policy risk New York courts could raise for the same clause language.
The same clause, analyzed once per jurisdiction module, demonstrates the core value of the architecture: identical input text produces materially different, jurisdiction-grounded risk assessments rather than one generic score applied everywhere.

What it enabled commercially

The client's legal and business stakeholders can get a jurisdiction-specific, defensible risk read on any MSA clause without leaving the document they are reviewing, and the platform is positioned to extend to Singapore, the United Kingdom, and India as additional self-contained jurisdiction modules rather than a rebuild.
WHY PFACTORIAL
This engagement draws on Pfactorial's applied research and compliance capability: encoding real jurisdictional legal expertise into a production AI tool through modular, evaluated architecture rather than a single generic prompt dressed up as legal analysis.
CS-011_ClauseGuard image 5
Figure - Service lines this engagement draws on.
Engagement enquiries Pfactorial Technologies works with legal and compliance teams looking to bring AI-assisted risk review into the tools professionals already use. If you are evaluating a jurisdiction-aware contract analysis or legal AI tool, we are happy to give you an honest read on scope, cost, and risk before anyone commits to anything. · pfactorial.ai
APPENDIX A - TECHNOLOGY STACK
The technology stack underpinning the system, grouped by the layer it serves.
CS-011_ClauseGuard image 6

Result and Analysis

ENGAGEMENT SNAPSHOT

A built and deployed sidebar add-on that scores individual Master Service Agreement clauses against jurisdiction-specific legal standards in real time, without ever leaving the document.

CS-011_ClauseGuard image 1
CS-011_ClauseGuard image 2
CS-011_ClauseGuard image 3
CS-011_ClauseGuard image 4
CS-011_ClauseGuard image 5
CS-011_ClauseGuard image 6