← Applied AI
Applied AI· 2 min read

Function Calling and Legal Research Tools

.NETAI EngineeringIndian Case Law

Summary

Deterministic C# tools for case metadata, passages, and a short constitutional catalog, with rejected blank input.

Companion code: 04-function-calling in indian-legal-ai-lab.

Previous: Part 3: Advanced Legal Retrieval

The model should not be the system of record for a citation, a statute sentence, or a span of a judgment. Those reads are C# methods that return `ToolResult<T>`.

Validation is the method, not a comment

`SearchCases` rejects a blank query and a `take` outside 1–20. An unknown method name becomes a failed `ToolResult` instead of an exception escaping the tool boundary. `GetCaseMetadata` returns the record with `Text` set to null, so a metadata call cannot leak the whole judgment. `GetJudgment` requires `maxChars` between 100 and 8000 and returns `No extracted text is stored for this judgment` when the manifest row has no file.

`GetPassage` looks up a `ChunkId`. The returned `RetrievedPassage` uses method `exact` when it comes from the chunker rather than from a ranked search.

The statute catalog is three provisions

`StatuteCatalog.Lookup` scans id, heading, and text. The catalog holds short public wording for Article 19(1)(a), Article 19(2), and Article 21. Article 21 in the catalog is: "No person shall be deprived of his life or personal liberty except according to procedure established by law." A query that matches nothing returns `No statute provision in the local catalog matched that query.`

Run it

dotnet run --project labs/04-function-calling

The lab prints the Thappar title, the Article 21 sentence, and `Query text is required.` from `SearchCases("")`. `Tools_reject_blank_input_and_unknown_tools` covers the blank query and the Article 21 hit.

These tools do not draft a pleading. The catalog is not the Constitution.

Next

Part 5: An MCP Server in C#

Verified in this revision

`ResearchAgent` accepts an `IChatClient`. `TryModelToolsAsync` registers `search_cases` and executes it only when the response contains `FunctionCallContent` for that name. `Agent_executes_a_model_selected_tool` injects a client that returns that call. The default `GroundedChatClient` returns no tool call, so the fixed search, judgment, and statute sequence still runs.

More in Applied AI