AI
Pass

AI Lease Analyzer Agent Skill — Extract and Explain Lease Terms via API

AI Lease Analyzer Agent Skill

Analyze lease agreements and extract key terms, red flags, and tenant questions via the AI Pass API. Use this skill when an agent needs to process rental or commercial lease documents.

Skill Overview

  • Input: Lease text (string)
  • Output: Structured analysis with summary, red flags, clauses, and questions
  • Model: gpt-5 via AI Pass
  • Auth: $AIPASS_API_KEY environment variable

Skill File

name: lease-analyzer
description: Analyze lease agreements and extract key terms, flag unusual clauses, and generate tenant questions
parameters:
  lease_text:
    type: string
    description: Full text of the lease agreement to analyze
  lease_type:
    type: string
    description: Type of lease (residential, commercial, month-to-month)
    default: "residential"
  focus:
    type: string
    description: Focus area (full, red-flags, financial, termination)
    default: "full"
returns:
  type: object
  description: Analysis object with summary, red_flags, clauses, questions fields

Implementation

import requests
import re
import os

AIPASS_API_KEY = os.environ["$AIPASS_API_KEY"]

def analyze_lease(
    lease_text: str,
    lease_type: str = "residential",
    focus: str = "full"
) -> dict:
    """
    Analyze a lease agreement and extract key information.
    
    Args:
        lease_text: Full text of the lease (truncated to 8000 chars)
        lease_type: Type of lease (residential, commercial, month-to-month)
        focus: Analysis focus (full, red-flags, financial, termination)
    
    Returns:
        dict with keys: summary, red_flags, clauses, questions, raw
    """
    # Truncate if needed — GPT-5 handles long docs but this keeps costs predictable
    text = lease_text[:8000]
    
    prompt = f"""Analyze this {lease_type} lease with focus on: {focus}.

Format your response exactly as:

SUMMARY:
[2-3 sentence overview of lease type, duration, rent, key dates]

RED FLAGS:
[List as: REDFLAG: [Name]: [What it means and why concerning]]
[If none: REDFLAG: None identified]

CLAUSE BREAKDOWN:
[CLAUSE: [Section Name]: [Plain English explanation]]

QUESTIONS:
[QUESTION: [Specific question to ask landlord before signing]]

LEASE:
{text}"""
    
    response = requests.post(
        "https://aipass.one/apikey/v1/chat/completions",
        headers={
            "Authorization": f"Bearer {AIPASS_API_KEY}",
            "Content-Type": "application/json"
        },
        json={
            "model": "gpt-5",
            "temperature": 1,
            "max_tokens": 16000,
            "messages": [
                {
                    "role": "system",
                    "content": "You are a tenant rights expert who explains legal documents clearly. Identify unusual, one-sided, or potentially harmful clauses. Do not provide legal advice."
                },
                {"role": "user", "content": prompt}
            ]
        },
        timeout=120
    )
    
    content = response.json()["choices"][0]["message"]["content"]
    
    # Parse sections
    summary_match = re.search(r'SUMMARY[:\s]+([\s\S]*?)(?=RED FLAGS:|$)', content, re.I)
    flags_match = re.search(r'RED FLAGS[:\s]+([\s\S]*?)(?=CLAUSE BREAKDOWN:|$)', content, re.I)
    clauses_match = re.search(r'CLAUSE BREAKDOWN[:\s]+([\s\S]*?)(?=QUESTIONS:|$)', content, re.I)
    questions_match = re.search(r'QUESTIONS[:\s]+([\s\S]*?)$', content, re.I)
    
    # Extract red flags as list
    flags_text = flags_match.group(1) if flags_match else ""
    red_flags = re.findall(r'REDFLAG:\s*(.+)', flags_text)
    
    # Extract clauses as list of dicts
    clauses_text = clauses_match.group(1) if clauses_match else ""
    clauses = []
    for m in re.finditer(r'CLAUSE:\s*([^:]+):\s*(.+)', clauses_text):
        clauses.append({"name": m.group(1).strip(), "explanation": m.group(2).strip()})
    
    # Extract questions as list
    questions_text = questions_match.group(1) if questions_match else ""
    questions = re.findall(r'QUESTION:\s*(.+)', questions_text)
    
    return {
        "summary": summary_match.group(1).strip() if summary_match else "",
        "red_flags": red_flags,
        "clauses": clauses,
        "questions": questions,
        "raw": content
    }


# Example usage
if __name__ == "__main__":
    sample_lease = """
    LEASE AGREEMENT
    Term: 12 months beginning August 1, 2026
    Monthly Rent: $2,400 due on the 1st
    Security Deposit: $4,800 (two months)
    Landlord may enter premises with 12 hours notice for any reason.
    Tenant may not sublease without written permission.
    Lease auto-renews for 12 months unless 90-day written notice given.
    Tenant responsible for all repairs under $500.
    """
    
    analysis = analyze_lease(
        lease_text=sample_lease,
        lease_type="residential",
        focus="full"
    )
    
    print("SUMMARY:", analysis["summary"])
    print("RED FLAGS:", analysis["red_flags"])
    print("QUESTIONS:", analysis["questions"])

Notes for Agents

  • temperature: 1 and max_tokens: 16000 are required for GPT-5
  • Text is limited to 8,000 chars; for longer leases, chunk and analyze in sections
  • Response time: 30–90 seconds for full analysis
  • The structured parsing falls back to raw if section headers aren't found

API Quick Reference

  • Endpoint: POST https://aipass.one/apikey/v1/chat/completions
  • Model: gpt-5
  • Auth: Bearer $AIPASS_API_KEY
  • Get API Key: Developer Dashboard → API Keys

Live App

aipass.one/apps/lease-analyzer