Legal contract analysis
Overview
This use case demonstrates how you can use the GenAI Builder Snaps to create a Legal Assistant that analyzes contracts.
Problem
Law firms face the challenge of analyzing contracts. Law firms struggle with change management as each partner is an individual profit center with control over their own processes. This makes it difficult to standardize contract analysis approaches across the firm. Contracts can be lengthy and contain a vast amount of detailed information. Analyzing these documents thoroughly requires significant time and effort, especially when dealing with multiple contracts simultaneously. Contracts may contain inconsistencies, typographical errors, or outdated terms. Identifying and resolving these issues is essential to ensure the contract's enforceability and to avoid potential disputes.
Additionally, law firms handle a wide variety of contracts across many industries rather than large volumes of similar contracts, limiting their ability to develop standardized analysis methods. Law firms may face resource constraints, including limited time, budget, and personnel. Efficiently managing these resources while maintaining the quality of contract analysis can be a significant challenge.
Solution
Developing a comprehensive AI-driven system that integrates with existing information can effectively address the challenge of analyzing legal contracts. This solution leverages existing redlined contracts to redline parts of a contract that are inconsistent with them.
Understanding the Solution
This use case demonstrates how to use the GenAI Builder Snaps to create a Legal Contract Analysis pipeline integration with a chatbot that redlines invalid language in the contract. This example consists of two pipelines:
- Indexer: Loads data from the source document. This pipeline extracts text from 4 PDF files breaks it into chunks, generates embeddings for each chunk using Azure OpenAI, and indexes the embeddings in Pinecone for search.
- Retriever: Retrieves data to answer questions. This pipeline connects to an AI chatbot using Azure OpenAI services. It takes in the test contract, generates embeddings using the Azure OpenAI Embedder Snap, queries similar embeddings in Pinecone, constructs a context for the Azure OpenAI Prompt Generator Snap, and passes it to the Azure OpenAI Chat Completions Snap to generate a response.
- Access to a Pinecone instance (sign up for a free account at https://www.pinecone.io) with an existing index
- Valid Azure OpenAI API Key Account or OpenAI API Key Account to access the resources from Azure OpenAI or OpenAI
- Zip file of 5 total PDFs: 4 sample contracts and 1 to test.
- Download the patterns from the SnapLogic Public Pattern Library
If you cannot find the patterns in the Pattern Library, you can download them from here:
- Indexer pipeline: Download this pipeline.
- Retriever pipeline: Download this pipeline.
- Sample legal contracts and redlining text contract: Download this zip file for the PDF collection.
Indexer pipeline
In this example, we will load data into a vector database using the Indexer pipeline because it populates the Pinecone Index.- Import the Indexer pattern pipeline. (Download this pipeline)
- Configure the File Reader Snap to read the four
PDF contracts that will provide the answers to questions from users. In the
File field, upload the source document. In this example, we
upload a number of redlined legal contracts.
Tip: You can use the File Reader and upload the PDFs one at a time. - Leave the PDF ParserSnap with default settings.
- Open the Azure OpenAI Embedder Snap and click
on the Account tab to create a new account.
- Enter a meaningful name for the account and replace
myendpoint
with the relevant name for your Azure OpenAI endpoint. - Validate and save your new account. If the account setup is successful, return to the Settings tab of the Snap.
- Enter a meaningful name for the account and replace
- Open the Azure OpenAI Embedder Snap and configure the settings as follows. Note: Alternatively, you can use the OpenAI Embedder Snap, but you might need to replace the Embedder in the Pattern or import the appropriate one for which you have an account.
- Configure the Mapper Snap to map the
output of the Embedder Snap to the Pinecone Upsert Snap.
- Map the $embedding object from the Embedder Snap to the $values object in Pinecone.
- Map the metadata object in Pinecone by mapping $original.chunk to $metadata.chunk.
- Map $metadata.source to redlined legal contracts.pdf
—this allows the Retriever pipeline to
return the source file to answer a question.
- Open the Pinecone Upsert Snap and click the
Account tab to create a new account with your
Pinecone API Key. Validate it to make sure it works.
- Save your account and return to the Settings tab.
- Configure the Pinecone Upsert Snap to retrieve existing indexes in
Pinecone. Note: You cannot create an Index spontaneously, so you must ensure it already exists in Pinecone (or create one with the Pinecone web interface).
- Optional. Set your Namespace. Namespaces in
Pinecone create a logical separation between vectors within an index and
can be created spontaneously during pipeline execution.
- Validate the pipeline to verify the data in the output preview. Execute the pipeline when you are ready to commit your data to Pinecone.
Retriever pipeline
This example pipeline demonstrates how to redline the text contract by using the data loaded into the Pinecone vector database from the Indexer pipeline.- Import the Retriever pattern pipeline (Download the pipeline).
- In the Asset Palette on the left, search for the File Reader Snap, and drag it onto the canvas. Use the Binary to Document Snap to connect it to the Azure OpenAI Embedder Snap.
- In the File Reader Snap settings, upload the legal document PDF you want to analyze. For example:
Furniture_Company CONTRACT AGREEMENT This Contract Agreement (Agreement) is entered into as of Oct 20 2023, by and between: Furniture_Company, a California corporation, with its principal place of business at furnitures (Company), and ACME_Coporation, a California corporation, with its principal place of business at wholesale (Counterparty). 1. SCOPE OF SERVICES: Company agrees to provide the following services to Counterparty (the Services): Furniture_Company is dedicated to providing ACME_Coporation with a comprehensive suite of exceptional wholesale distribution services. Our commitment extends beyond mere transactional exchanges to foster a strategic partnership that ensures ACME_Coporation’s success in the competitive furniture market. We offer an extensive range of services, including meticulous sourcing and procurement of high-quality furniture products, tailored to meet the diverse preferences of ACME_Coporation’s clientele. Our team of experts engages in thorough market research and trend analysis to curate a collection that aligns seamlessly with current design trends and consumer demands. From classic pieces exuding timeless elegance to contemporary designs pushing the boundaries of innovation, our inventory caters to various styles and preferences. Company agrees to provide products other than furniture as part of the Services. 2. TERM: The term of this Agreement shall commence on Nov 1 2023 and shall continue until Nov 1 2024, unless terminated earlier in accordance with the provisions of this Agreement. 3. PAYMENT: Counterparty agrees to pay the Company the sum of $10,000.00 for the Services. Payment shall be made in monthly installments. Payment terms are flexible, allowing the Counterparty to make payments at their discretion. 4. CONFIDENTIALITY: Both parties agree to maintain the confidentiality of any proprietary or confidential information disclosed during the course of this Agreement. 5. INTELLECTUAL PROPERTY: Any intellectual property created as a result of the Services shall be the exclusive property of Furniture_Company, unless otherwise agreed upon in writing. 6. TERMINATION: Either party may terminate this Agreement with written notice if the other party breaches a material term of this Agreement. In case of termination, Counterparty agrees to pay Furniture_Company a penalty of $5 million. 7. INDEMNIFICATION: Counterparty agrees to indemnify and hold Company harmless from any claims, damages, or liabilities arising out of or related to the Services. 8. GOVERNING LAW: This Agreement shall be governed by and construed in accordance with the laws of the state of California. The Counterpart agrees to engage in discriminatory practices. 9. ENTIRE AGREEMENT: The validity of this Agreement is unaffected even if either party is not of sound mind. This Agreement constitutes the entire understanding between the parties and supersedes all prior agreements or understandings, whether oral or written. Company guarantees a 500% return on Counterparty's investment without any basis. 10. AMENDMENTS: No amendment or modification of this Agreement shall be valid unless in writing and signed by both parties. IN WITNESS WHEREOF, the parties hereto have executed this Contract Agreement as of the date first above written. Furniture_Company By: Ethan Reynolds Date: Oct 20 2023 ACME_Coporation By: Olivia Mitchell Date: Oct 20 2023
- Open the Azure OpenAI Embedder Snap.
- Click the Account tab and select the account you created in the Indexer example.
- Click the suggestion icon for the Deployment ID and choose the Deployment ID you previously chose in the Indexer example.
- Set the Text to embed field to $content.
- Add a Mapper Snap, and configure the following entry in the
Mapping table:
$embedding:$vector
- Open the Pinecone Query Snap and click the Account tab to create a new account with your Pinecone API Key. Validate it to make sure it works.
- Configure the Pinecone Query Snap as shown below.
Tip: Optional. In the Namespace field, select your existing namespace if you have created one.
- Open the Mapper Snap connected to
the Pinecone Query Snap, and configure it as shown below:
- Click on the Azure OpenAI Prompt Generator
Snap to set up your prompt.
- Click the Edit prompt and ensure your default
prompt appears as shown below.
- On lines 4-6 there is mustache templating with the values
{{#context}} {{source}} {{/context}}
which is the same as the jsonPath($, "$context[*].source") from the Mapper Snap that we just configured. You can customize the prompt with the following:Instruction 1: Please learn the following articles that mark invalid sentences with [Red Line] before this sentence: {{#results}}{{chunk}} {{/results}} Could you please mark [Red Line] before invalid sentences with the following new article and display the whole article: {{original.original.prompt}} Instruction 2: Please add the following information to the end of answer and include all source with bullet point: The related context is retrieved from the following sources: {{#results}}{{source}} {{/results}} Answer:
- Click the Edit prompt and ensure your default
prompt appears as shown below.
- Open the Azure OpenAI Chat Completions Snap.
- Click the Account tab and select the account you created in the Indexer example.
- Click the suggestion icon () for the Deployment ID and choose the Deployment ID you previously chose in the Indexer example. This ID might differ from the one you chose in the previous Azure OpenAI Snap because we now need to select an LLM model instead of an embedding one.
- Validate the pipeline.
- Click the output preview of the Azure OpenAI Chat Completions Snap to display the
contract with the target portions indicated by
[Red Line]
as shown below.