Tool Registry That Validates Model-Generated Function Call Arguments

Last updated: November 29, 2026

Quick Overview

Design classes for a registry of tools that a chat model can call. Given a call with a tool name and a JSON string of arguments produced by the model, look up the tool, validate the arguments against its schema, run it, and return a structured result or a clear error the model can recover from.

OpenAI
Software Engineering Fundamentals
Software Engineer
OpenAI
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


Design classes for a registry of tools that a chat model can call. Given a call with a tool name and a JSON string of arguments produced by the model, look up the tool, validate the arguments against its schema, run it, and return a structured result or a clear error the model can recover from.

Function calling is a core OpenAI API feature, and the model sometimes emits malformed JSON, unknown parameters, or wrong types. This low-level design round checks class boundaries, extensibility for new tools, and whether errors are returned as data the model can read instead of crashing the request.

What the Interviewer Expects
  • Defines a Tool abstraction with a name, schema, and run method
  • Keeps parsing, validation, and execution as separate steps
  • Returns every validation error at once instead of failing on the first
  • Never raises on bad model output; returns structured errors
  • Rejects duplicate registrations and unknown tool names
  • Discusses where timeouts and permissions would plug in
Key Topics to Cover
object-oriented design
abstract base classes
input validation
function calling
error handling
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you support nested objects and arrays in the schema?
  • How would you run independent tool calls from one model turn in parallel?
  • How do you stop a tool from being called with arguments a user is not allowed to use?
  • How would you test this without calling real external services?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • Register tools with a name and a parameter schema (type, required, optional enum).
  • dispatch(call) parses the argument string, validates, executes, and returns {ok, result} or `{ok: False, erro...
High-Level Design

Tool is an abstract base class owning its schema and validation. Concrete tools only implement run. ToolRegistry maps names to instances and owns the dispatch pipeline: lookup, JSON parse, shape...


Submit Your Answer
Markdown supported