|
2 | 2 |
|
3 | 3 | ## Overview |
4 | 4 |
|
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 |
6 | 44 |
|
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. |
8 | 45 |
|
9 | 46 | ## Architecture |
10 | 47 |
|
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: |
13 | 53 |
|
14 | 54 |  |
15 | 55 |
|
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 | + |
17 | 61 |
|
18 | | - |
| 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 | + |
| 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 | + |
19 | 73 |
|
20 | 74 | ## Cost Analysis and Pricing |
21 | 75 |
|
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. |
23 | 81 |
|
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. |
25 | 89 |
|
26 | 90 | 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. |
27 | 91 |
|
28 | 92 | #### Claude 3.5 Haiku and Amazon Nova Lite |
29 | 93 | | Model | Input Tokens | Output Tokens | Cache Read Tokens | Cache Write Tokens | **Total Cost** | |
30 | 94 | |-------|-------------|---------------|-------------------|-------------------|---------------| |
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%** | |
34 | 98 |
|
35 | 99 | #### Claude 3.5 Sonnet v2 and Amazon Nova Pro (without prompt caching) |
36 | 100 | | Model | Input Tokens | Output Tokens | **Total Cost** | |
37 | 101 | |-------|-------------|---------------|---------------| |
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%** | |
41 | 105 |
|
42 | 106 | #### Claude 3.7 Sonnet and Amazon Nova Premier |
43 | 107 | | Model | Input Tokens | Output Tokens | Cache Read Tokens | Cache Write Tokens | **Total Cost** | |
44 | 108 | |-------|-------------|---------------|-------------------|-------------------|---------------| |
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%** | |
48 | 112 |
|
| 113 | +### Pricing Reference |
49 | 114 |
|
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. |
51 | 116 |
|
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 |
56 | 117 |
|
57 | | -### Pricing Reference |
| 118 | +## Documentation |
58 | 119 |
|
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). |
60 | 121 |
|
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 |
62 | 123 |
|
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. |
64 | 125 |
|
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. |
66 | 127 |
|
67 | | -``` |
68 | | -samples/contract-compliance-analysis |
69 | | -│ |
70 | | -├── backend # Backend |
71 | | -├── frontend # Frontend |
72 | | -``` |
| 128 | +### Installation |
73 | 129 |
|
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 |
75 | 131 |
|
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 |
78 | 133 |
|
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 | + ``` |
80 | 138 |
|
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?" |
82 | 142 |
|
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. |
84 | 150 |
|
| 151 | +Type `/quit` to exit the assistant. For more Q CLI options, run `q --help`. |
85 | 152 |
|
86 | 153 | # Content Security Legal Disclaimer |
87 | 154 | 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