value / scripts /validate_lease.py
bonita2026's picture
Upload 7 files
3b01fc7 verified
Raw History Blame Contribute Delete
19.4 kB
#!/usr/bin/env python3
"""
validate_lease.py — Lease completeness and risk checker by jurisdiction.
Usage:
python scripts/validate_lease.py --lease-file contract.txt --jurisdiction uk --party tenant
python scripts/validate_lease.py --lease-file lease.txt --jurisdiction spain --asset-type commercial
python scripts/validate_lease.py --lease-file nnn.txt --jurisdiction usa --asset-type retail
Output:
JSON with per-item status (PRESENT / AMBIGUOUS / ABSENT), counts,
jurisdiction-specific flags, and overall GREEN/YELLOW/RED status.
Note: Detection is keyword-based — FIRST PASS only.
All ABSENT and AMBIGUOUS items must be verified manually by a qualified lawyer.
"""
import argparse, json, sys, os
UNIVERSAL_ITEMS = [
{"id":"U01","name":"rent_and_payment_terms",
"keywords":["rent","renta","loyer","miete","payment","pago","mensualidad"],
"desc":"Rent amount, currency, payment frequency, late payment consequences",
"risk_if_absent":"CRITICAL — fundamental commercial term missing"},
{"id":"U02","name":"rent_escalation_review",
"keywords":["escalation","review","revision","actualizacion","indexation","CPI","IPC","RPI","increment"],
"desc":"Rent escalation mechanism: fixed %, CPI-linked, open market review, or stepped",
"risk_if_absent":"HIGH — no escalation = rent erodes in real terms over lease term"},
{"id":"U03","name":"security_deposit_or_guarantee",
"keywords":["deposit","deposito","guarantee","garantia","aval","bond","fianza","security"],
"desc":"Security deposit or bank guarantee: amount, form, draw conditions, return timeline",
"risk_if_absent":"HIGH — landlord has no security against default"},
{"id":"U04","name":"lease_term_and_commencement",
"keywords":["term","plazo","duration","commencement","expiry","vencimiento","inicio","lease period"],
"desc":"Lease start date, end date, total duration, conditions precedent to commencement",
"risk_if_absent":"CRITICAL — without defined term, lease cannot be properly valued or enforced"},
{"id":"U05","name":"permitted_use",
"keywords":["use","uso","permitted","permiso","purpose","actividad","destino","occupation"],
"desc":"Specific permitted use, exclusivity provisions, restrictions on use",
"risk_if_absent":"HIGH — tenant may use for incompatible purposes"},
{"id":"U06","name":"assignment_and_subletting",
"keywords":["assignment","cesion","subletting","subarriendo","transfer","consent","alienation"],
"desc":"Conditions for assignment and subletting: consent required, landlord response time",
"risk_if_absent":"MEDIUM — silence defaults to statutory position which varies by jurisdiction"},
{"id":"U07","name":"termination_and_default",
"keywords":["termination","resolucion","default","incumplimiento","breach","cure","remedy"],
"desc":"Termination rights, cure periods (monetary and non-monetary), consequences of default",
"risk_if_absent":"HIGH — no defined cure period creates uncertainty for both parties"},
{"id":"U08","name":"maintenance_and_repair",
"keywords":["maintenance","mantenimiento","repair","reparacion","upkeep","structural","fabric"],
"desc":"Allocation of maintenance obligations (structural vs non-structural, HVAC, common areas)",
"risk_if_absent":"MEDIUM — leads to disputes; defaults to statutory allocation"},
{"id":"U09","name":"insurance_requirements",
"keywords":["insurance","seguro","assurance","liability","responsabilidad","public liability","property insurance"],
"desc":"Required insurance types, minimum cover amounts, naming as additional insured",
"risk_if_absent":"MEDIUM — uninsured losses can exceed lease economics"},
{"id":"U10","name":"alterations_and_fit_out",
"keywords":["alteration","obras","fit-out","improvement","mejora","reinstatement","reposicion","reinstate"],
"desc":"Consent for alterations, ownership of improvements, reinstatement obligation at expiry",
"risk_if_absent":"MEDIUM — ownership disputes at expiry"},
{"id":"U11","name":"force_majeure",
"keywords":["force majeure","fuerza mayor","act of god","pandemic","pandemia","unavoidable","supervening"],
"desc":"Force majeure definition, rent abatement or termination right, maximum duration",
"risk_if_absent":"MEDIUM — post-COVID standard inclusion; absence creates uncertainty"},
{"id":"U12","name":"dispute_resolution_and_governing_law",
"keywords":["dispute","arbitration","arbitraje","litigio","court","tribunal","governing law","jurisdiction"],
"desc":"Governing law, jurisdiction, dispute resolution mechanism",
"risk_if_absent":"HIGH — parties default to potentially inconvenient or costly forum"},
{"id":"U13","name":"notices",
"keywords":["notice","notificacion","notification","address for service","direccion"],
"desc":"Notice method, service addresses, deemed receipt timing",
"risk_if_absent":"MEDIUM — invalid notices can defeat break clauses and renewal rights"},
{"id":"U14","name":"indemnity_and_liability_cap",
"keywords":["indemnity","indemnidad","liability","responsabilidad","cap","limitation","consequential"],
"desc":"Mutual indemnities, liability caps, exclusion of consequential losses",
"risk_if_absent":"HIGH — uncapped liability exposure"},
{"id":"U15","name":"rent_free_or_incentives",
"keywords":["rent free","rent-free","incentive","franquicia","holiday","contribution","fit out contribution"],
"desc":"Rent-free period, fit-out contribution, clawback if tenant exits early",
"risk_if_absent":"LOW — relevant if incentives are part of deal economics"},
]
JURISDICTION_ITEMS = {
"uk": [
{"id":"UK01","name":"lta_1954_status",
"keywords":["1954","LTA","security of tenure","contracting out","statutory declaration","38A","inside the act","outside the act"],
"desc":"LTA 1954: is lease inside or outside the Act? If outside: s.38A notice + statutory declaration required BEFORE execution",
"risk_if_absent":"CRITICAL — if contracting-out procedure not followed, tenant has statutory renewal rights"},
{"id":"UK02","name":"break_clause_conditions",
"keywords":["break","option to break","break notice","break condition","vacant possession","break date"],
"desc":"Break clause: notice period (typically 6 months), pre-conditions (no arrears, vacant possession, covenant compliance)",
"risk_if_absent":"HIGH if break expected — poorly drafted conditions frequently prevent exercise"},
{"id":"UK03","name":"service_charge_rics",
"keywords":["service charge","RICS","management fee","sinking fund","service cost","audit service charge"],
"desc":"Service charge: RICS Professional Statement 2018 compliance, audit rights, annual cap",
"risk_if_absent":"MEDIUM — without cap/audit rights, service charge exposure is uncontrolled"},
{"id":"UK04","name":"dilapidations_and_schedule_of_condition",
"keywords":["dilapidation","schedule of condition","yield up","repair covenant","reinstate","decorating covenant"],
"desc":"Dilapidations provisions; schedule of condition if property not in prime condition",
"risk_if_absent":"HIGH for tenant — without schedule of condition, liable for full repair standard at expiry"},
{"id":"UK05","name":"snda",
"keywords":["SNDA","subordination","non-disturbance","attornment","lender consent","mortgagee"],
"desc":"SNDA if property is mortgaged — protects tenant's lease if lender forecloses",
"risk_if_absent":"HIGH if property mortgaged — foreclosure could extinguish tenant lease"},
{"id":"UK06","name":"rent_review_mechanism",
"keywords":["rent review","open market","upward only","OMR","market rent","review date"],
"desc":"Rent review type (open market / indexed / stepped), frequency, upward-only clause",
"risk_if_absent":"MEDIUM — no review mechanism means rent fixed for entire term"},
],
"spain": [
{"id":"ES01","name":"ipc_indexation",
"keywords":["IPC","actualizacion","revision anual","INE","indice","IPC anual","actualizacion renta"],
"desc":"Rent update: IPC (INE) or agreed alternative (LAU Art.18) — must be express if not IPC",
"risk_if_absent":"MEDIUM — defaults to IPC; if different indexation intended, must be explicit"},
{"id":"ES02","name":"deposito_2_meses",
"keywords":["deposito","fianza","2 mensualidades","LAU 36","garantia adicional","aval bancario"],
"desc":"Mandatory 2-month deposit (LAU Art.36 for local); additional guarantee if agreed",
"risk_if_absent":"HIGH — 2-month deposit is legally mandatory; non-provision is non-compliance"},
{"id":"ES03","name":"break_clause",
"keywords":["clausula de salida","break","resolucion anticipada","penalizacion","preaviso salida"],
"desc":"Early termination clause: notice period, penalty, conditions",
"risk_if_absent":"LOW-MEDIUM — without break clause, contract binding for full term"},
{"id":"ES04","name":"iva_y_retencion_fiscal",
"keywords":["IVA","21%","impuesto valor","retencion","IRPF","19%","factura","sujeto a IVA"],
"desc":"IVA (21%) on rent; IRPF retention (19%) if tenant is a company or professional",
"risk_if_absent":"HIGH — unclear fiscal treatment creates tax compliance risk for both parties"},
{"id":"ES05","name":"prorroga_y_vencimiento",
"keywords":["prorroga","prorroga tacita","vencimiento","renovacion","notificacion vencimiento"],
"desc":"Renewal/extension provisions, tacit renewal conditions, notice requirements for non-renewal",
"risk_if_absent":"MEDIUM — LAU provisions apply by default; may not match parties' intentions"},
],
"usa": [
{"id":"US01","name":"lease_type_classification",
"keywords":["NNN","triple net","gross","modified gross","full service","net lease","absolute net"],
"desc":"Lease type explicitly stated: FSG / Modified Gross / NNN / Absolute NNN — determines cost allocation",
"risk_if_absent":"CRITICAL — without explicit type, CAM and expense allocation is ambiguous"},
{"id":"US02","name":"cam_definition_and_cap",
"keywords":["CAM","common area","operating expense","expense stop","cap","gross-up","audit right"],
"desc":"CAM definition (inclusions/exclusions), annual cap (typically 5%), gross-up, audit rights",
"risk_if_absent":"HIGH for tenant — uncapped CAM creates unquantifiable occupancy cost"},
{"id":"US03","name":"snda_and_estoppel",
"keywords":["SNDA","estoppel","subordination","non-disturbance","attornment","lender"],
"desc":"SNDA and estoppel certificate requirements (required for CMBS and most institutional financing)",
"risk_if_absent":"HIGH — without SNDA, tenant lease may be extinguished on foreclosure"},
{"id":"US04","name":"cotenancy_clause",
"keywords":["co-tenancy","cotenancy","anchor","dark","go-dark","percentage rent"],
"desc":"Co-tenancy clause: rent reduction or termination right if anchor tenant vacates (retail)",
"risk_if_absent":"MEDIUM for retail — without co-tenancy, tenant bears full anchor risk"},
{"id":"US05","name":"holdover_provision",
"keywords":["holdover","hold over","month to month","150%","200%","holdover rent"],
"desc":"Holdover rent (typically 150% of last monthly rent) if tenant stays after expiry",
"risk_if_absent":"MEDIUM — defaults to month-to-month at existing rent"},
{"id":"US06","name":"renewal_option",
"keywords":["renewal","option to renew","extension option","FMR","fair market rent","notice of renewal"],
"desc":"Renewal option: number, notice deadline (typically 6-12 months before expiry), rent determination",
"risk_if_absent":"LOW — no statutory renewal rights in US; without option, no right to renew"},
],
"india": [
{"id":"IN01","name":"lock_in_period",
"keywords":["lock-in","lock in","lockin","minimum term","early exit penalty","lock in period"],
"desc":"Lock-in period during which neither party can terminate (typically 3 years for commercial)",
"risk_if_absent":"HIGH for landlord — tenant can exit without penalty"},
{"id":"IN02","name":"gst_on_rent",
"keywords":["GST","18%","CGST","SGST","input tax credit","ITC","GST registration","GSTIN"],
"desc":"GST at 18% on commercial rent if landlord's aggregate turnover > INR 20L; ITC eligibility",
"risk_if_absent":"HIGH — GST non-compliance exposes landlord to demand, interest and penalty"},
{"id":"IN03","name":"tds_on_rent",
"keywords":["TDS","tax deduction","194-I","194IB","Form 16A","26QC","TDS certificate"],
"desc":"TDS obligations: Sec.194-I (10%) for companies; Sec.194-IB (5%) for individuals > INR 50K/month",
"risk_if_absent":"HIGH — non-deduction makes payer assessee-in-default"},
{"id":"IN04","name":"leave_and_license_vs_lease",
"keywords":["leave and license","leave & license","licence","license fee","licensor","licensee"],
"desc":"Clarify if agreement is lease or leave & license — different legal protections and eviction remedies",
"risk_if_absent":"HIGH — misclassification applies wrong legal regime"},
{"id":"IN05","name":"rera_compliance",
"keywords":["RERA","Real Estate Regulatory","RERA number","RERA registration","promoter"],
"desc":"If residential: RERA registration number and compliance with RERA obligations",
"risk_if_absent":"HIGH if residential — RERA non-compliance is a criminal offence"},
],
"france": [
{"id":"FR01","name":"bail_commercial_9_ans",
"keywords":["9 ans","bail commercial","3-6-9","résiliation triennale","renouvellement","décret 1953"],
"desc":"Bail commercial: 9-year minimum; tenant triennal exit confirmed; statutory renewal right",
"risk_if_absent":"CRITICAL — non-compliance with bail commercial rules invalidates the lease structure"},
{"id":"FR02","name":"indexation_ilc_ilat",
"keywords":["ILC","ILAT","INSEE","révision","loyer indexé","indice"],
"desc":"Rent indexation: ILC (shops) or ILAT (offices/logistics) — published quarterly by INSEE",
"risk_if_absent":"MEDIUM — defaults to ILC; if different index intended, must be expressed"},
{"id":"FR03","name":"charges_loi_pinel",
"keywords":["charges","travaux","article 606","gros travaux","repartition charges","loi pinel"],
"desc":"Charges allocation per Loi Pinel 2014 reform: list of charges recoverable from tenant vs landlord Art.606",
"risk_if_absent":"HIGH — Loi Pinel requires explicit allocation; silence creates disputes"},
],
"germany": [
{"id":"DE01","name":"schriftform_written_form",
"keywords":["Schriftform","written form","signature","unterschrift","§550","BGB 550"],
"desc":"Written form (BGB §550): leases >1 year must be fully in writing to run for full term",
"risk_if_absent":"CRITICAL — incomplete written form = lease treated as indefinite-term, terminable with notice"},
{"id":"DE02","name":"nebenkosten_allocation",
"keywords":["Nebenkosten","Betriebskosten","operating costs","Nebenkostenabrechnung","Heizkostenabrechnung"],
"desc":"Nebenkosten (operating costs) allocation, annual reconciliation obligation",
"risk_if_absent":"HIGH — without clear allocation, landlord cannot recover all operating costs"},
{"id":"DE03","name":"mietzins_anpassung",
"keywords":["Mietanpassung","Indexmiete","CPI","Verbraucherpreisindex","Staffelmiete","Wertsicherungsklausel"],
"desc":"Rent adjustment: index-linked (Indexmiete) or stepped (Staffelmiete) — both require express agreement",
"risk_if_absent":"MEDIUM — no adjustment: rent fixed for entire term"},
],
}
def check_item(text, item):
text_lower = text.lower()
hits = sum(1 for k in item["keywords"] if k.lower() in text_lower)
total = len(item["keywords"])
if hits == 0:
return "ABSENT"
elif hits >= max(1, int(total * 0.4)):
return "PRESENT"
else:
return "AMBIGUOUS"
def evaluate_lease(text, jurisdiction, party, asset_type):
all_items = UNIVERSAL_ITEMS + JURISDICTION_ITEMS.get(jurisdiction, [])
results, absent_ids, ambiguous_ids = [], [], []
for item in all_items:
status = check_item(text, item)
results.append({"id":item["id"],"name":item["name"],"status":status,
"desc":item["desc"],"risk_if_absent":item.get("risk_if_absent","")})
if status == "ABSENT": absent_ids.append(item["id"])
elif status == "AMBIGUOUS": ambiguous_ids.append(item["id"])
n_absent, n_ambiguous = len(absent_ids), len(ambiguous_ids)
if n_absent == 0 and n_ambiguous <= 2:
overall = "GREEN"; msg = "Lease appears substantially complete. Verify AMBIGUOUS items manually."
elif n_absent <= 2 and (n_absent + n_ambiguous) <= 5:
overall = "YELLOW"; msg = f"{n_absent} ABSENT and {n_ambiguous} AMBIGUOUS items. Legal review required."
else:
overall = "RED"; msg = f"{n_absent} ABSENT items — material gaps. Do not execute without legal review."
return {
"jurisdiction": jurisdiction, "party_perspective": party, "asset_type": asset_type,
"summary": {"total_items_checked": len(all_items), "present": len(all_items)-n_absent-n_ambiguous,
"ambiguous": n_ambiguous, "absent": n_absent,
"overall_status": overall, "message": msg},
"absent_item_ids": absent_ids, "ambiguous_item_ids": ambiguous_ids, "detail": results,
"note": ("Keyword-based FIRST PASS only. PRESENT = keywords found, not that clause is legally adequate. "
"All items must be reviewed by a qualified lawyer in the applicable jurisdiction."),
}
def main():
parser = argparse.ArgumentParser(description="Lease completeness checker by jurisdiction.")
parser.add_argument("--lease-file", required=True)
parser.add_argument("--jurisdiction", default="generic",
choices=["uk","spain","usa","india","germany","france","generic"])
parser.add_argument("--party", default="landlord", choices=["landlord","tenant"])
parser.add_argument("--asset-type", default="commercial",
choices=["commercial","retail","industrial","residential","office"])
args = parser.parse_args()
if not os.path.exists(args.lease_file):
print(json.dumps({"error": f"File not found: {args.lease_file}"})); sys.exit(1)
with open(args.lease_file, encoding="utf-8", errors="replace") as f:
text = f.read()
if len(text.strip()) < 50:
print(json.dumps({"error": "File appears empty or too short"})); sys.exit(1)
print(json.dumps(evaluate_lease(text, args.jurisdiction, args.party, args.asset_type),
indent=2, ensure_ascii=False))
if __name__ == "__main__":
main()