Function Calling and Legal Research Tools
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-callingThe 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
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
Advanced Legal Retrieval
Keyword, hashing-vector, and hybrid search on the same question, plus the SQL a pgvector store would run.
An MCP Server in C#
A JSON-RPC handler exposes five read-only research tools and refuses any tool name outside that list.
LLM Fundamentals in C#
A supplied judgment can be summarized only from passages you pass in. The same client, with no passage, names a citation that the catalog rejects.