Skip to content

Classify Contract Types

In this example, we’ll be classifying various contracts by type, using LlamaClassify, and the llama-cloud SDK. When provided with a file, we’ll classify it either as a co_branding contract or an affiliate_agreement.

As an example, we’ll be making use of the CUAD dataset, which includes various contracts such as: Affiliate Agreements, Co-Branding contracts, Franchise contracts and more.

The example we go through below is also replicable within the LlamaCloud as well, where you will also be able to create classification rules via the UI, instead of defining them in code:

pip install llama-cloud>=1.0

To start off, we recommend downloading a few contracts from the ‘Affiliate Agreements’ and ‘Co-Branding’ sections from the CUAD dataset.

To get started, make sure you provide your Llama Cloud API key.

You can set it as an environment variable LLAMA_CLOUD_API_KEY or pass it directly to the SDK at runtime.

from llama_cloud import AsyncLlamaCloud
project_id = "your-project-id"
organization_id = "your-organization-id"
client = AsyncLlamaCloud(api_key=os.environ["LLAMA_CLOUD_API_KEY"])

For this example, we’ll narrow down the scope to classifying between co_branding and affiliate_agreements types:

rules = [
{
"type": "affiliate_agreements",
"description": "This is a contract that outlines an affiliate agreement",
},
{
"type": "co_branding",
"description": "This is a contract that outlines a co-branding deal/agreement",
},
]

Finally, we can classify a file (or files):

file_obj = await client.files.create(
file="CybergyHoldingsInc_Affliate Agreement.pdf",
purpose="classify",
)
file_id = file_obj.id
result = await client.classifier.classify_file_path(
file_ids=[file_id],
rules=rules,
)
classification = result.items[0].result
print("Classification Result: " + classification.type)
print("Classification Reason: " + classification.reasoning)

Once classification is complete, the results will include not only the contract type the file was classified as, but also the reasoning for this classification by LlamaClassify. For example, in this case this is the result we got:

Classification Result: affiliate_agreements
Classification Reason: The document is titled 'MARKETING AFFILIATE AGREEMENT' and repeatedly refers to one party as the 'Marketing Affiliate.' The agreement outlines the rights and obligations of the 'Marketing Affiliate' (MA) to market, sell, and support certain technology products, and details the relationship between the company and the affiliate. There is no mention of joint branding, shared trademarks, or collaborative marketing under both parties' brands, which would be indicative of a co-branding agreement. The content is entirely consistent with an affiliate agreement, where one party (the affiliate) is authorized to market and sell the products of another company, rather than a co-branding arrangement. Therefore, the best match is 'affiliate_agreements' with very high confidence.