Skip to content
Guide
Classify
Examples

Classify Contract Types

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

We’ll use the CUAD dataset, which includes various contract types: Affiliate Agreements, Co-Branding contracts, Franchise contracts, and more.

The same workflow can be replicated in the LlamaCloud UI, where you can create classification rules visually instead of in code.

Terminal window
pip install llama-cloud>=1.6

Download a few contracts from the Affiliate Agreements and Co-Branding sections of the CUAD dataset.

Make sure you have a LlamaCloud API key. Set it as an environment variable or pass it directly to the SDK.

import os
from llama_cloud import LlamaCloud
client = LlamaCloud(api_key=os.environ["LLAMA_CLOUD_API_KEY"])

For this example we’ll classify between co_branding and affiliate_agreements:

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",
},
]

Upload a file and classify it:

import time
file_obj = client.files.create(
file="CybergyHoldingsInc_Affliate Agreement.pdf",
purpose="classify",
)
# Create a classify job
job = client.classify.create(
file_id=file_obj.id,
configuration={"rules": rules, "mode": "FAST"}, # or "MULTIMODAL"
)
# Poll until complete
status = client.classify.get(job.id)
while status.status == "PENDING":
time.sleep(2)
status = client.classify.get(job.id)
if status.result:
print("Classification Result: " + status.result.type)
print("Classification Reason: " + status.result.reasoning)

Once classification is complete, the results include the predicted contract type and the model’s reasoning. For example:

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.