compare_requirements
Compare regulatory requirements across multiple EU regulations on specific topics like incident reporting or risk assessment. Identifies matching articles with text snippets to show how different regulations address the same topic.
Instructions
Search and compare articles across multiple regulations on a specific topic. Returns matching articles from each regulation with text snippets showing how they address the topic. Uses full-text search with relevance ranking to find related requirements.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| topic | Yes | Topic to compare (e.g., "incident reporting", "risk assessment") | |
| regulations | Yes | Regulations to compare (e.g., ["DORA", "NIS2"]) |
Implementation Reference
- src/tools/compare.ts:142-216 (handler)The main implementation of the `compare_requirements` tool, which searches for regulations based on a topic and its synonyms, extracts timeline-related information, and returns a structured comparison.
export async function compareRequirements( db: DatabaseAdapter, input: CompareInput ): Promise<CompareResult> { const { topic, regulations } = input; // Get synonym terms for expanded search const synonyms = getSynonyms(topic); const searchTerms = [topic, ...synonyms]; const comparisons: RegulationComparison[] = []; for (const regulation of regulations) { // Search with original topic + synonym terms, then merge results const allResults: Map<string, { article: string; snippet: string; relevance: number }> = new Map(); for (const term of searchTerms) { const results = await searchRegulations(db, { query: term, regulations: [regulation], limit: 5, }); for (const result of results) { const existing = allResults.get(result.article); if (!existing || result.relevance > existing.relevance) { allResults.set(result.article, { article: result.article, snippet: result.snippet, relevance: result.relevance, }); } } } // Sort by relevance and take top 5 const mergedResults = Array.from(allResults.values()) .sort((a, b) => b.relevance - a.relevance) .slice(0, 5); // Get full article text for timeline extraction const articles: string[] = []; const requirements: string[] = []; let combinedText = ''; for (const result of mergedResults) { articles.push(result.article); requirements.push(result.snippet.replace(/>>>/g, '').replace(/<<</g, '')); // Get full text for timeline extraction const fullArticleResult = await db.query( `SELECT text FROM articles WHERE regulation = $1 AND article_number = $2`, [regulation, result.article] ); if (fullArticleResult.rows.length > 0) { combinedText += ' ' + (fullArticleResult.rows[0] as { text: string }).text; } } const timelines = extractTimelines(combinedText); comparisons.push({ regulation, requirements, articles, timelines, }); } return { topic, regulations: comparisons, }; } - src/tools/compare.ts:4-19 (schema)Data structures for the `compare_requirements` tool input and output.
export interface CompareInput { topic: string; regulations: string[]; } export interface RegulationComparison { regulation: string; requirements: string[]; articles: string[]; timelines?: string; } export interface CompareResult { topic: string; regulations: RegulationComparison[]; } - src/tools/registry.ts:173-195 (registration)Tool registration for `compare_requirements` in the tool registry.
{ name: 'compare_requirements', description: 'Search and compare articles across multiple regulations on a specific topic. Returns matching articles from each regulation with text snippets showing how they address the topic. Uses full-text search with relevance ranking to find related requirements.', inputSchema: { type: 'object', properties: { topic: { type: 'string', description: 'Topic to compare (e.g., "incident reporting", "risk assessment")', }, regulations: { type: 'array', items: { type: 'string' }, description: 'Regulations to compare (e.g., ["DORA", "NIS2"])', }, }, required: ['topic', 'regulations'], }, handler: async (db, args) => { const input = args as unknown as CompareInput; return await compareRequirements(db, input); }, },