Check Required Parameters Are Present
Problem Statement
Before dispatching a tool call, verify every required parameter is present. Report the missing ones so the agent can ask for them.
Background
A tool schema lists a set of required parameter names. Validation returns the sorted list of required names absent from the provided arguments. An empty list means the call is ready to execute.
Your Task
Implement:
def missing_params(args, required):
- args: dict of provided arguments.
- required: list of required parameter names.
- Return the sorted list of required names not in args.
Input Format
- args (dict), required (list of strings).
Output Format
- A sorted list of strings.
Sample
print(missing_params({"city": "NYC"}, ["city", "date"]))
Output:
['date']
Example:
print(missing_params({"city": "NYC"}, ["city", "date"]))['date']
- Identify the provided arguments and the required parameters: the input dictionary contains the key
"city", and the required list is["city", "date"]. - Check each required parameter against the provided arguments to determine presence:
"city"is found in the arguments, while"date"is absent. - Collect the missing parameters into a list, resulting in
["date"]. - Sort the list of missing parameters alphabetically to ensure a consistent output order; since there is only one element, the list remains
["date"]. - The final output is
['date']
Constraints:
- Compare only names (values may be anything, including None).
- A required name present with any value counts as provided.
- Return the missing names sorted ascending.
1. Background Knowledge
In AI agents and function calling frameworks, a tool is defined by a schema that specifies its parameters. Each parameter can be marked as required or optional. Before an agent dispatches a tool call, it must validate that all required parameters are present in the provided arguments. If any are missing, the agent should not execute the call but instead report which parameters are absent so it can prompt the user for the missing information.
This validation step is a form of input validation or schema checking. The core operation is a set difference: given the set of required parameter names and the set of keys actually provided in the arguments dictionary, we want the names that are in the required set but not in the provided set. This is a fundamental operation in data processing and is directly supported by Python's set type.
The result should be returned as a sorted list to ensure deterministic output, which is important for testing and for consistent user-facing messages.
2. Algorithm Approach
This is a straightforward set difference problem. The approach is:
- Convert the list of required parameter names into a set for efficient membership testing.
- Convert the keys of the args dictionary into a set (or use the dict directly for membership checks).
- Compute the difference: required names that are not in the provided arguments.
- Sort the resulting list and return it.
The key insight is that dictionary key lookup in Python is O(1) on average, and set operations like difference are also O(n), making this very efficient.
3. Step-by-Step Strategy
- Step 1: Accept the two inputs: args (a dict) and required (a list of strings).
- Step 2: Create a set from required to enable fast membership checks. Alternatively, you can iterate over required and check each name against args.
- Step 3: For each name in required, check whether it exists as a key in args. If it does not exist, add it to a collection of missing names.
- Step 4: Convert the collection of missing names to a list and sort it alphabetically.
- Step 5: Return the sorted list. An empty list means all required parameters are present.
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
Editor locked
The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.