Skip to main content
Article
contract-managementlegal-techai-agentworkflow-automationcompliancerisk-managementironcladapi-integration

Automate Contract Review with Ironclad's AI Agent

Use Ironclad's Contract Management Agent to automatically extract key terms, track obligations, and flag risks. This guide shows how to set up a workflow to analyze new agreements against your company's legal playbook, saving hours of manual review.

intermediate30 min5 steps
The play
  1. Set Up a Workflow Template
    First, define the process for a specific contract type. In Ironclad, navigate to the Workflow Designer and create a new template (e.g., 'Third-Party NDA Review'). Add a document upload step and ensure the 'AI-Powered Contract Analysis' option is enabled. This tells the Contract Management Agent to activate for any contract launched from this template.
  2. Build Your AI Playbook
    Train the agent on your company's standards. Within the workflow template, go to the 'AI Playbook' section. Add key clauses you want to track (e.g., 'Term and Termination', 'Confidentiality Period', 'Governing Law'). For each clause, define your preferred language and acceptable variations. The Contract Management Agent will use this playbook to compare and redline incoming contracts.
  3. Launch a Contract for Analysis
    Test your setup with a real contract. Start a new workflow using the template you created. When prompted, upload a third-party contract document (e.g., a PDF or .docx file). Once you launch the workflow, the Contract Management Agent begins its analysis in the background.
  4. Review AI-Generated Insights
    Once the analysis is complete (usually in a few minutes), open the workflow to see the results. The agent populates a summary with extracted key terms, obligations, and dates. It will also display a 'Smart Detection' panel that flags clauses deviating from your playbook, providing risk scores and suggested redlines.
  5. Automate Ingestion via API
    Integrate contract review into other systems by programmatically launching workflows. Use the Ironclad API to upload a contract and start the analysis process without manual UI interaction. The starter code shows how to do this with Python.
Starter code
import requests
import json
import os

# --- Configuration ---
# 1. Get your API Token from Ironclad: Company Settings > API > Create API Token
# 2. Get your Workflow Template ID: Open the template in Workflow Designer, the ID is in the URL (e.g., .../design/wft_...)
# 3. Set your Ironclad domain (e.g., 'your-company.ironcladapp.com')
IRONCLAD_DOMAIN = os.environ.get('IRONCLAD_DOMAIN', 'your-company.ironcladapp.com')
API_TOKEN = os.environ.get('IRONCLAD_API_TOKEN', 'YOUR_IRONCLAD_API_TOKEN')
TEMPLATE_ID = 'wft_...'
CONTRACT_FILE_PATH = './sample-agreement.pdf' # Create a dummy PDF for testing

def launch_contract_review(template_id, file_path, counterparty_name):
    """Uploads a contract and launches an Ironclad review workflow."""
    api_url = f'https://{IRONCLAD_DOMAIN}/api/v1/workflows'
    headers = {
        'Authorization': f'Bearer {API_TOKEN}',
        'Accept': 'application/json'
    }

    # These fields must match the fields defined in your Workflow Designer template.
    form_fields = {
        'counterpartyName': counterparty_name,
        'agreementDate': '2023-10-27'
    }

    form_data = {
        'workflowTemplateId': (None, template_id),
        'formFields': (None, json.dumps(form_fields))
    }

    if not os.path.exists(file_path):
        print(f"Error: File not found at {file_path}. Please create a sample PDF.")
        return

    with open(file_path, 'rb') as f:
        files = {
            'document': (os.path.basename(file_path), f, 'application/pdf')
        }

        print(f"Uploading '{file_path}' to start workflow '{template_id}'...")
        try:
            response = requests.post(api_url, headers=headers, data=form_data, files=files)
            response.raise_for_status()
            workflow = response.json()
            print("\n--- Success! ---")
            print(f"Workflow launched with ID: {workflow['id']}")
            print(f"Track progress: https://{IRONCLAD_DOMAIN}/workflows/{workflow['id']}")
        except requests.exceptions.HTTPError as e:
            print(f"\n--- API Error --- ")
            print(f"Status Code: {e.response.status_code}")
            print(f"Response: {e.response.text}")
        except Exception as e:
            print(f"An unexpected error occurred: {e}")

if __name__ == '__main__':
    # Create a dummy file for the script to run
    if not os.path.exists(CONTRACT_FILE_PATH):
        with open(CONTRACT_FILE_PATH, 'w') as f:
            f.write("This is a dummy file for the Ironclad API script.")
        print(f"Created dummy file: {CONTRACT_FILE_PATH}")

    if 'YOUR_IRONCLAD_API_TOKEN' in API_TOKEN or 'wft_...' not in TEMPLATE_ID:
        print("Please update API_TOKEN and TEMPLATE_ID before running.")
    else:
        launch_contract_review(
            template_id=TEMPLATE_ID,
            file_path=CONTRACT_FILE_PATH,
            counterparty_name='Test Counterparty Inc.'
        )
Automate Contract Review with Ironclad's AI Agent — Action Pack