Skip to content

Commit 42b24f5

Browse files
authored
Merge pull request #245 from mrgiba/main
feat: Contract Compliance Analysis V2
2 parents 3ac0303 + ef8d89a commit 42b24f5

File tree

335 files changed

+54546
-17421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

335 files changed

+54546
-17421
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This repo provides samples to demonstrate how to build your own Generative AI so
1616
|[Amazon Bedrock Agents](samples/bedrock-agent/)| This sample provides a sample application which deploys an Amazon Bedrock Agent and Knowledge Base backed by an OpenSearch Serverless Collection and documents in S3. It demonstrates how to use the [Amazon Bedrock CDK construct](https://github.com/awslabs/generative-ai-cdk-constructs/tree/main/src/cdk-lib/bedrock). |Backend|TypeScript|
1717
|[Python Samples](samples/python-samples/)| This project showcases the utilization of the 'generative-ai-cdk-constructs' package from the Python Package Index (PyPI).| Backend | Python|
1818
|[.NET Samples](samples/dotnet-samples/)| This project showcases the utilization of the 'Cdklabs.GenerativeAiCdkConstructs' package from nuget library.| Backend | .NET|
19-
|[Contract Compliance Analysis](samples/contract-compliance-analysis/)| This project automates the analysis of contracts by splitting them into clauses, determining clause types, evaluating compliance against a customer's legal guidelines, and assessing overall contract risk based on the number of compliant clauses. This is achieved through a workflow that leverages Large Language Models via Amazon Bedrock. | Backend + Frontend | Python for Backend, TypeScript (React) for Frontend |
19+
|[Contract Compliance Analysis](samples/contract-compliance-analysis/)| This prototype can potentially help you make your contract compliance process more efficient, leveraging Generative Artificial Intelligence (GenAI) to evaluate contract clauses against predefined guidelines and to provide feedback on adherence to standards applicable to you, based on your instructions. This is achieved through workflows that leverages Large Language Models via Amazon Bedrock. | Backend + Frontend | Python for Backend, TypeScript (React) for Frontend |
2020
|[Multimodal RAG solution](samples/multimodal-rag)| This project showcases Amazon Bedrock multimodal features using [Amazon Bedrock Data Automation](https://aws.amazon.com/bedrock/bda/) (BDA) combined with Amazon Bedrock Knowledge Bases for a RAG-based chatbot. | Backend + Frontend | Python for Backend, TypeScript (React) for Frontend |
2121
|[RFP Answers with GenAI](samples/rfp-answer-generation/)| This project provides guidance on how you can use Knowledge Bases for Amazon Bedrock with custom transformations to create draft answers for Request for Proposal (RFP) documents, streamlining the answer of new potential contracts. This is achieved through a workflow that leverages Large Language Models via Amazon Bedrock. | Backend + Frontend | Python for Backend, TypeScript (React) for Frontend |
2222
| [Code Expert](samples/code-expert/) | This project addresses the scalability limitations of manual code reviews by leveraging artificial intelligence to perform expert code reviews automatically. It leverages the [Bedrock Batch Step Functions CDK construct](https://github.com/awslabs/generative-ai-cdk-constructs/blob/main/src/patterns/gen-ai/aws-bedrock-batch-stepfn/README.md). | Backend | Python for Backend and Demo, TypeScript for CDK |
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
history
1+
history
2+
**/**/history*
3+
**/**/.DS_Store
4+
.kiro
5+
.amazonq
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Contract Compliance Analysis - Setup Guide
2+
3+
This guide covers the key steps to deploy and run the Contract Compliance Analysis prototype.
4+
5+
## Follow READMEs in order (please read each one in full)
6+
1. `backend/README.md` - Deploy backend stack and load guidelines
7+
2. `frontend/README.md` - Configure and run frontend
8+
9+
## What to check before starting the deployment
10+
- Check if there is AWS profile configure
11+
- Check the AWS account number and ask user to confirm it's the expected one
12+
- Get AWS default account region and ask user to confirm it's the expected one
13+
14+
## General deployment/configuration recommendations
15+
- Follow README instructions in sequence. Make sure not to miss instructions.
16+
- For running `cdk deploy`, `cdk bootstrap` or any other command that will log much content, run the command redirecting the log to a temporary folder
17+
- It's recommended to run cdk deploy having '--require-approval=never' flag, otherwise cdk deploy will prompt for typing (y/n) but the user will not see, since it's running behind q chat / execute_bash
18+
- Legislation Check is an optional feature, but feel free to ask user if they want the feature to be configured - but alert about the costs (OpenSearch)
19+
- For frontend, rather than running the command to start the web application, just tell the user what the command is
20+
21+
## Additional Steps for MainBackendStack stack
22+
23+
### 1. Enable Bedrock Model Access
24+
Follow the "Enable Bedrock Model Access (Prerequisite)" section in `backend/README.md` before deploying the stack.
25+
26+
### 2. Get Stack Outputs for Frontend
27+
```bash
28+
aws cloudformation describe-stacks --stack-name MainBackendStack --query "Stacks[0].Outputs"
29+
```
30+
31+
### 3. Create Cognito User
32+
Follow the "Add users to Cognito User Pool" section in `backend/README.md`

samples/contract-compliance-analysis/README.md

Lines changed: 106 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,86 +2,153 @@
22

33
## Overview
44

5-
This is a project to automate the compliance analysis of contracts, leveraging Generative Artificial Intelligence (GenAI) to evaluate contract clauses against predefined guidelines and provide feedback on their adherence to the required standards.
5+
This prototype can potentially help you make your contract compliance process more efficient, leveraging Generative Artificial Intelligence (GenAI) to evaluate contract clauses against predefined guidelines and to provide feedback on adherence to standards applicable to you, based on your instructions.
6+
7+
This prototype is powered by Large Language Models (LLMs) available on Amazon Bedrock, capable of understanding common legal terms and concepts. The LLMs are used to perform advanced natural language tasks like classifying contractual clauses and evaluating whether a particular clauses aligns with predefined guidelines.
8+
9+
**NOTE: Contract Compliance Analysis prototype does not provide legal advice, nor does it serve as a substitute for professional advice. Legal matters may be complex and fact-specific, so you should make your own assessment and consider seeking the advice of a licensed legal profession for any legal matters you encounter.**
10+
11+
## Folder Structure
12+
13+
This sample application codebase is organized into these key folders:
14+
15+
```
16+
samples/contract-compliance-analysis
17+
18+
├── backend # Backend
19+
├── frontend # Frontend
20+
```
21+
22+
## Getting started
23+
24+
> **Warning**
25+
> This sample allows you to interact with models from third party providers. Your use of the third-party generative AI (GAI) models is governed by the terms provided to you by the third-party GAI model providers when you acquired your license to use them (for example, their terms of service, license agreement, acceptable use policy, and privacy policy).
26+
27+
> You are responsible for ensuring that your use of the third-party GAI models comply with the terms governing them, and any laws, rules, regulations, policies, or standards that apply to you.
28+
29+
> You are also responsible for making your own independent assessment of the third-party GAI models that you use, including their outputs and how third-party GAI model providers use any data that might be transmitted to them based on your deployment configuration. AWS does not make any representations, warranties, or guarantees regarding the third-party GAI models, which are "Third-Party Content" under your agreement with AWS. This sample is offered to you as "AWS Content" under your agreement with AWS.
30+
31+
To deploy this project, follow the instructions available in the README files located at the **backend** and **frontend** folders, in that sequence.
32+
33+
## Key Features
34+
35+
- **Automated Contract Analysis**: Validates, processes, classifies, and evaluates contract clauses against your guidelines with risk assessment
36+
- **Multi-Language AI Analysis**: Generate analysis reports in English, Spanish, or Portuguese based on user selection
37+
- **Multi-Contract Type Support**: Define and manage multiple contract types (service agreements, employment contracts, etc.) with type-specific guidelines
38+
- **Web Application**: User interface for managing contract types, guidelines, and viewing analysis results
39+
- **AI-Generated Evaluation Questions**: Automatically create compliance questions from guideline definitions
40+
- **Contract Import**: Bootstrap new contract types by extracting guidelines from reference contracts
41+
- **Configurable Risk Thresholds**: Customize risk classification criteria per contract type
42+
- **Flexible Model Selection**: Configure different foundation models for specific tasks via parameter store
43+
- **Optional Legislation Compliance**: AI agent with knowledge base integration for verifying clauses against legal documents
644

7-
The project is powered by Large Language Models (LLM) available on Amazon Bedrock, capable of understanding legal terminology and concepts. LLMs are used to perform advanced natural language tasks, such as clause classification and compliance evaluation according to predefined guidelines.
845

946
## Architecture
1047

11-
The core of this solution is the contract analysis workflow, which leverages Large Language Models to perform advanced natural language tasks to evaluate clauses against predefined guidelines.
12-
Different storage components are used for the input, intermediate steps, analysis output, and the guidelines information. Additionally, there are components for the user interface, comprising web application hosting, authentication, and integration services.
48+
This prototype leverages AWS managed services and Large Language Models to automate contract compliance analysis. The architecture consists of multiple workflows that work together to validate contracts against your guidelines and optionally verify compliance with legislation.
49+
50+
### High-Level Architecture
51+
52+
The system includes serverless workflows for contract processing, a web interface for managing contract types and viewing results, authentication via Amazon Cognito, and storage for contracts, guidelines, and analysis results:
1353

1454
![High Level Architecture](./images/high-level-architecture.png)
1555

16-
Zooming in to the contract analysis workflow:
56+
### Guidelines Compliance Workflow
57+
58+
The core workflow processes uploaded contracts through multiple stages: validation, preprocessing (clause extraction), classification (identifying clause types using LLMs), evaluation (checking compliance against guidelines), and risk assessment (calculating overall contract risk):
59+
60+
![Guidelines Compliance Architecture](./images/guidelines-compliance-architecture.png)
1761

18-
![High Level Architecture](./images/contract-analysis-architecture.png)
62+
### Legislation Compliance Workflow (Optional)
63+
64+
When enabled, this workflow uses an AI agent with access to a knowledge base of legislation documents to verify that contract clauses comply with applicable laws and regulations:
65+
66+
![Legislation Compliance Architecture](./images/legislation-compliance-architecture.png)
67+
68+
### Contract Import Workflow
69+
70+
This workflow uses LLMs to automatically extract contract type information and guidelines from reference contracts, enabling rapid onboarding of new contract types without manual guideline creation:
71+
72+
![Contract Import Architecture](./images/contract-import-architecture.png)
1973

2074
## Cost Analysis and Pricing
2175

22-
This solution demonstrates significant cost savings by using Amazon Nova models compared to traditional Claude models. The following analysis is based on processing the **sample contract included with this solution** using the default guidelines.
76+
This section analyzes the primary cost drivers for this prototype and demonstrates significant cost savings by using Amazon Nova models compared to Claude models.
77+
78+
### Primary Cost Drivers
79+
80+
**1. Amazon Bedrock** - LLM inference costs for contract processing. Varies based on contract size, guidelines complexity, selected model, and usage volume.
2381

24-
### Model Cost Comparison
82+
**2. Amazon OpenSearch Serverless (Optional)** - Required only if legislation compliance is deployed. **Minimum cost: ~$350/month** (2 OCUs at ~$0.24/OCU-hour), continuous even when idle.
83+
84+
**3. Other AWS Services** - Step Functions, DynamoDB, Lambda, S3, and API Gateway use pay-per-use pricing. Typically much smaller than Bedrock and OpenSearch costs.
85+
86+
### Bedrock Model Cost Comparison
87+
88+
> **Note**: The following cost estimates are based on actual processing of the **sample contract included with this prototype** using the default guidelines. Your actual costs may vary depending on contract size, guidelines complexity, and usage patterns.
2589
2690
The following analysis shows token usage and costs for processing the included sample contract. Some of the scenarios have [Amazon Bedrock prompt caching](https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html) enabled.
2791

2892
#### Claude 3.5 Haiku and Amazon Nova Lite
2993
| Model | Input Tokens | Output Tokens | Cache Read Tokens | Cache Write Tokens | **Total Cost** |
3094
|-------|-------------|---------------|-------------------|-------------------|---------------|
31-
| **Claude 3.5 Haiku** | 98,166<br>$0.08 | 40,570<br>$0.16 | 570,255<br>$0.05 | 16,293<br>$0.02 | **$0.30** |
32-
| **Amazon Nova Lite** | 89,140<br>$0.07 | 45,733<br>$0.11 | 534,275<br>$0.11 | 15,265<br>$0.00 | **$0.02** |
33-
| | | | | **Savings:** | **🟢 92%** |
95+
| **Claude 3.5 Haiku** | 96,627<br>$0.08 | 38,273<br>$0.15 | 556,512<br>$0.04 | 16,368<br>$0.02 | **$0.29** |
96+
| **Amazon Nova Lite** | 88,024<br>$0.01 | 35,208<br>$0.01 | 567,691<br>$0.01 | 15,343<br>$0.00 | **$0.02** |
97+
| | | | | **Savings:** | **🟢 93%** |
3498

3599
#### Claude 3.5 Sonnet v2 and Amazon Nova Pro (without prompt caching)
36100
| Model | Input Tokens | Output Tokens | **Total Cost** |
37101
|-------|-------------|---------------|---------------|
38-
| **Claude 3.5 Sonnet v2** | 684,737<br>$2.05 | 65,927<br>$0.99 | **$3.04** |
39-
| **Amazon Nova Pro** | 625,677<br>$0.50 | 33,493<br>$0.11 | **$0.61** |
40-
| | | **Savings:** | **🟢 80%** |
102+
| **Claude 3.5 Sonnet v2** | 706,407<br>$4.24 | 58,021<br>$1.74 | **$5.98** |
103+
| **Amazon Nova Pro** | 577,291<br>$0.46 | 30,384<br>$0.10 | **$0.56** |
104+
| | | **Savings:** | **🟢 91%** |
41105

42106
#### Claude 3.7 Sonnet and Amazon Nova Premier
43107
| Model | Input Tokens | Output Tokens | Cache Read Tokens | Cache Write Tokens | **Total Cost** |
44108
|-------|-------------|---------------|-------------------|-------------------|---------------|
45-
| **Claude 3.7 Sonnet** | 98,189<br>$0.29 | 65,927<br>$0.99 | 586,548<br>$0.18 | 16,293<br>$0.06 | **$1.52** |
46-
| **Amazon Nova Premier** | 92,706<br>$0.23 | 53,539<br>$0.69 | 541,100<br>$0.34 | 15,460<br>$0.00 | **$1.26** |
47-
| | | | | **Savings:** | **🟢 17%** |
109+
| **Claude 3.7 Sonnet** | 94,944<br>$0.28 | 80,574<br>$1.21 | 572,880<br>$0.17 | 16,368<br>$0.01 | **$1.67** |
110+
| **Amazon Nova Premier** | 91,076<br>$0.23 | 49,836<br>$0.62 | 529,550<br>$0.33 | 15,575<br>$0.00 | **$1.18** |
111+
| | | | | **Savings:** | **🟢 29%** |
48112

113+
### Pricing Reference
49114

50-
### Cost Factors
115+
For the most up-to-date pricing information, refer to the [Amazon Bedrock Pricing](https://aws.amazon.com/bedrock/pricing/) page.
51116

52-
Actual costs depend on several factors:
53-
- **Guidelines complexity**: More detailed guidelines require more tokens
54-
- **Contract size**: Larger contracts consume more input tokens
55-
- **Selected LLM**: Different models have different pricing structures
56117

57-
### Pricing Reference
118+
## Documentation
58119

59-
For the most up-to-date pricing information, refer to the [Amazon Bedrock Pricing](https://aws.amazon.com/bedrock/pricing/) page.
120+
For comprehensive information including architecture, security, deployment, and operations, see the [Technical Documentation](./documentation/technical-documentation.adoc).
60121

61-
> **Note**: The cost analysis above is based on processing the sample contract included with this solution using the default guidelines. Your actual costs may vary depending on your specific contract sizes, guidelines complexity, and usage patterns.
122+
## Optional: Use Amazon Q Developer CLI Assistant to setup project
62123

63-
## Folder Structure
124+
For additional setup assistance, you can optionally use Amazon Q Developer CLI, an AI assistant that can help guide you through the deployment process, troubleshoot issues, and answer questions about AWS services.
64125

65-
This sample application codebase is organized into these key folders:
126+
> **Security Note**: Amazon Q CLI can read files and execute AWS CLI commands. Review all suggested commands before execution, especially those that create, modify, or delete AWS resources. Use in development environments only.
66127
67-
```
68-
samples/contract-compliance-analysis
69-
70-
├── backend # Backend
71-
├── frontend # Frontend
72-
```
128+
### Installation
73129

74-
## Getting started
130+
Install Amazon Q Developer CLI by following the instructions at: https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/command-line-installing.html
75131

76-
> **Warning**
77-
> This sample allows you to interact with models from third party providers. Your use of the third-party generative AI (GAI) models is governed by the terms provided to you by the third-party GAI model providers when you acquired your license to use them (for example, their terms of service, license agreement, acceptable use policy, and privacy policy).
132+
### Usage
78133

79-
> You are responsible for ensuring that your use of the third-party GAI models comply with the terms governing them, and any laws, rules, regulations, policies, or standards that apply to you.
134+
1. Start the interactive assistant from the project root directory:
135+
```bash
136+
q chat
137+
```
80138

81-
> You are also responsible for making your own independent assessment of the third-party GAI models that you use, including their outputs and how third-party GAI model providers use any data that might be transmitted to them based on your deployment configuration. AWS does not make any representations, warranties, or guarantees regarding the third-party GAI models, which are “Third-Party Content” under your agreement with AWS. This sample is offered to you as “AWS Content” under your agreement with AWS.
139+
2. Ask for help with setup, for example:
140+
- "Help me set up this contract compliance analysis project"
141+
- "What are the steps to deploy this application?"
82142

83-
To deploy this project, follow the instructions available in the README files located at the **backend** and **frontend** folders, in that sequence.
143+
The assistant will have access to this project's documentation and could help with:
144+
- Step-by-step deployment guidance
145+
- AWS CLI commands and troubleshooting
146+
- Stack output retrieval and frontend configuration
147+
- Cognito user creation
148+
149+
**Important**: Always review and understand commands before executing them. Q CLI will ask for confirmation before making changes to your system or AWS resources.
84150

151+
Type `/quit` to exit the assistant. For more Q CLI options, run `q --help`.
85152

86153
# Content Security Legal Disclaimer
87154
The sample code; software libraries; command line tools; proofs of concept; templates; or other related technology (including any of the foregoing that are provided by our personnel) is provided to you as AWS Content under the AWS Customer Agreement, or the relevant written agreement between you and AWS (whichever applies). You should not use this AWS Content in your production accounts, or on production or other critical data. You are responsible for testing, securing, and optimizing the AWS Content, such as sample code, as appropriate for production grade use based on your specific quality control practices and standards. Deploying AWS Content may incur AWS charges for creating or using AWS chargeable resources, such as running Amazon EC2 instances or using Amazon S3 storage.

0 commit comments

Comments
 (0)