legal_attempt_completion
Formats legal analysis results into structured documents, extracts citations, and presents findings with professional clarity for legal opinions and summaries.
Instructions
A specialized tool for presenting legal analysis results and conclusions. This tool formats legal conclusions with proper structure, extracts and formats citations, and provides a professional legal document format.
When to use this tool:
When presenting the final results of a legal analysis
When summarizing legal findings and recommendations
When providing a structured legal opinion
When concluding a legal reasoning process
Key features:
Automatic detection of legal domains
Proper legal document formatting
Citation extraction and formatting
Structured sections for clear communication
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | No | A CLI command to execute (optional) | |
| context | No | Additional context about the legal issue (optional) | |
| result | Yes | The legal analysis result or conclusion |
Implementation Reference
- src/index.ts:681-728 (handler)Primary handler function for executing the legal_attempt_completion tool. Validates input, detects legal domain, formats the result using helper functions if necessary, and constructs the tool response.function processLegalAttemptCompletion(input: unknown): { content: Array<{ type: string; text: string }>; isError?: boolean } { try { const data = input as Record<string, unknown>; // Validate input if (!data.result || typeof data.result !== 'string') { throw new Error('Invalid result: must be a string'); } // Detect domain from result and context const textToAnalyze = data.context ? `${data.result} ${data.context}` : data.result as string; const domain = detectDomain(textToAnalyze); // Format the result with proper legal structure let result = data.result as string; // If result doesn't have a good structure, apply template if (!hasGoodStructure(result)) { result = applyTemplateStructure(result, domain); } // Prepare response return { content: [{ type: "text", text: JSON.stringify({ result, command: data.command, detectedDomain: domain, formattedCitations: [] }, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: JSON.stringify({ error: error instanceof Error ? error.message : String(error), status: 'failed' }, null, 2) }], isError: true }; } }
- src/index.ts:133-167 (registration)Tool registration object defining the name, description, and input schema for 'legal_attempt_completion'.const LEGAL_ATTEMPT_COMPLETION_TOOL: Tool = { name: "legal_attempt_completion", description: `A specialized tool for presenting legal analysis results and conclusions. This tool formats legal conclusions with proper structure, extracts and formats citations, and provides a professional legal document format. When to use this tool: - When presenting the final results of a legal analysis - When summarizing legal findings and recommendations - When providing a structured legal opinion - When concluding a legal reasoning process Key features: - Automatic detection of legal domains - Proper legal document formatting - Citation extraction and formatting - Structured sections for clear communication`, inputSchema: { type: "object", properties: { result: { type: "string", description: "The legal analysis result or conclusion" }, command: { type: "string", description: "A CLI command to execute (optional)" }, context: { type: "string", description: "Additional context about the legal issue (optional)" } }, required: ["result"] } };
- src/index.ts:840-842 (registration)Dispatch logic in the CallToolRequestSchema handler that invokes the processLegalAttemptCompletion function for 'legal_attempt_completion' tool calls.if (request.params.name === "legal_attempt_completion") { return processLegalAttemptCompletion(request.params.arguments); }
- src/shared/types.ts:57-71 (schema)TypeScript interfaces defining the input and output structures for the legal_attempt_completion tool.export interface LegalAttemptCompletionInput { result: string; command?: string; context?: string; } /** * Legal attempt completion response data */ export interface LegalAttemptCompletionResponse { result: string; command?: string; detectedDomain: string; formattedCitations: string[]; }
- src/index.ts:452-460 (helper)Helper function to detect the legal domain from input text using predefined regex patterns.function detectDomain(text: string): string { // Check each domain's patterns for (const [domain, patterns] of Object.entries(legalDomainPatterns)) { if (patterns.some(pattern => pattern.test(text))) { return domain; } } return "legal_reasoning"; // Default domain }
- src/index.ts:733-745 (helper)Helper function to check if the input result already has good legal document structure (sections, bullets, paragraphs).function hasGoodStructure(result: string): boolean { // Check for section headers (numbered or with clear titles) const hasNumberedSections = /\n\s*\d+\.\s+[A-Z]/.test(result); const hasTitledSections = /\n\s*[A-Z][a-zA-Z\s]+:/.test(result); // Check for bullet points const hasBulletPoints = /\n\s*[-•*]\s+/.test(result); // Check for clear paragraphs const hasClearParagraphs = result.split('\n\n').length >= 3; return (hasNumberedSections || hasTitledSections) && (hasBulletPoints || hasClearParagraphs); }
- src/index.ts:750-778 (helper)Helper function to apply domain-specific template structure to unformatted results, adding titles and template sections.function applyTemplateStructure(result: string, domain: string): string { // Get domain-specific completion template const template = domainCompletionTemplates[domain] || domainCompletionTemplates["legal_reasoning"]; // Add a title based on domain let formattedResult = ''; switch (domain) { case 'ansc_contestation': formattedResult += 'Legal Analysis Summary:\n\n'; break; case 'consumer_protection': formattedResult += 'Consumer Protection Analysis:\n\n'; break; case 'contract_analysis': formattedResult += 'Contract Analysis Report:\n\n'; break; default: formattedResult += 'Legal Analysis Report:\n\n'; } // Add a brief introduction formattedResult += `${result}\n\n`; // Add template structure formattedResult += template.split('\n\n').slice(1).join('\n\n'); return formattedResult; }