Skip to main content

Legal Agent

The Legal Agent is responsible for contract reviews, compliance checks, and legal risk analysis. It supports teams without legal expertise by helping them identify contract-related risks in advance.

Important Disclaimer

The analysis provided by the Legal Agent is for reference purposes only. Decisions regarding legally binding contracts, litigation responses, and regulatory compliance must be reviewed by a qualified attorney.

// src/agents/legal.ts
import { query } from "@anthropic-ai/claude-agent-sdk";
import { AgentResponse } from "../shared/types";
import { extractText, log } from "../shared/utils";

const LEGAL_SYSTEM_PROMPT = `You are a corporate legal expert.
You perform contract reviews, risk analysis, and compliance checks.
Clearly state that all analysis results are for 'reference purposes only', and recommend attorney review for important matters.
Clearly classify risks into 3 levels (High/Medium/Low).`;

export async function runLegalAgent(task: string): Promise<AgentResponse> {
log("LEGAL", `Task started: ${task.slice(0, 40)}...`);

const response = await query({
prompt: `${LEGAL_SYSTEM_PROMPT}\n\n---\n\n${task}`,
options: {
maxTurns: 10,
tools: ["Read"] // Legal is read-only (modifications prohibited)
}
});

const result = extractText(response);
const hasHighRisk = result.includes("High") ||
result.includes("Immediate") ||
result.includes("Attorney review needed");

log("LEGAL", `Task completed (High Risk: ${hasHighRisk ? "Yes" : "No"})`);

return {
department: "legal",
result,
confidence: "medium", // Legal always requires expert verification
escalationNeeded: hasHighRisk,
actionItems: hasHighRisk ? ["Request attorney review"] : []
};
}

1. Contract Risk Reviewโ€‹

> Legal Team: Please review the risk clauses in the following SaaS subscription contract.
[Attach contract content]

Agent Response Example:

## Contract Risk Analysis Report

### ๐Ÿ”ด High Risk Clauses (Immediate Review Required)
1. Article 12 Data Ownership
Current: "All data generated during the use of the service is owned by the supplier"
Issue: Risk of losing customer data ownership
Recommendation: Request modification to "Customer data is owned by the customer..."

2. Article 18 Limitation of Liability
Current: No limit on damages
Issue: Exposure to unlimited liability
Recommendation: Negotiate a cap of "within 2 times the annual contract amount"

### ๐ŸŸก Medium Risk Clauses (Negotiation Recommended)
3. Article 7 Price Increase Clause
Current: Can increase up to 20% annually
Issue: Uncertainty in budget planning
Recommendation: Negotiate a 5% cap or link to CPI

### ๐ŸŸข General Review Completed
- Contract period, termination conditions, intellectual property clauses have no issues

### Final Recommendation
Modification requests for clauses 1 and 2 are mandatory after attorney review

2. Privacy Policy Compliance Checkโ€‹

async function checkPrivacyCompliance(
privacyPolicy: string,
regulations: string[]
) {
return runLegalAgent(
`Please check if the following privacy policy complies with the regulations.

Applicable regulations: ${regulations.join(", ")}

Check items:
1. Specification of collection items and purposes
2. Clarity of retention period
3. Notice of third-party provision/entrustment
4. Information on data subject rights (access/correction/deletion/transfer)
5. Information of the privacy protection officer

Privacy Policy:
${privacyPolicy}`
);
}

3. NDA (Non-Disclosure Agreement) Standard Reviewโ€‹

async function reviewNDA(ndaContent: string, companyRole: string) {
return runLegalAgent(
`Please review the NDA where our company is the ${companyRole} (Provider/Recipient).

NDA Content:
${ndaContent}

Review points:
- Scope of definition of confidential information (whether it is too broad or too narrow)
- Duration of obligation (generally 2-5 years)
- Exception clauses (publicly known information, independent development, etc.)
- Remedies in case of breach
- Competent court and governing law

Final: Whether it can be signed + Requested modifications`
);
}

4. Regulation Change Monitoringโ€‹

async function complianceUpdate(
newRegulation: string,
currentPolicies: string
) {
return runLegalAgent(
`Please analyze the compliance impact according to the new regulation changes.

New regulation: ${newRegulation}
Current policies: ${currentPolicies}

Analysis:
1. Items needing change among current policies
2. New policies/procedures that need to be introduced
3. Implementation deadline and priority
4. Penalties for violation (fines, etc.)
5. Response roadmap (Immediate/Short-term/Medium-term)`
);
}
// Additional safety measures applied to Legal Agent
const LEGAL_HIGH_RISK_KEYWORDS = [
"lawsuit", "litigation", "damages", "criminal", "fair trade", "monopoly"
];

export async function runLegalAgentSafe(task: string): Promise<AgentResponse> {
const result = await runLegalAgent(task);

// Immediate escalation upon detecting high-risk keywords
const hasHighRiskKeyword = LEGAL_HIGH_RISK_KEYWORDS.some(kw =>
task.includes(kw) || result.result.includes(kw)
);

return {
...result,
escalationNeeded: true, // Legal always human review
result: result.result + "\n\n---\nโš ๏ธ **This analysis is for reference only. Consult an attorney for legal decisions.**"
};
}
Legal Agent Usage Tips
  • Provide the entire text at once for contract reviews (avoid fragmenting context)
  • Include checklists by frequently used contract types in the system prompt
  • Automatically send a Slack notification to the legal person in charge upon a high-risk determination