Sub topic 8
Deciding What Is Required and What Is Optional
This chapter assumes you can read a JSON Schema properties block, you have called an LLM API with tools before, and you can follow short Python. It builds on the search_orders definition from earlier chapters, where only customer_id is required and status, created_after, and limit are optional.
What the model does with `required`
The required array is a signal to the model. It is also a contract you must enforce yourself.
When the model writes a tool call, it reads your schema and decides which arguments to include. A parameter listed in required is one the model will try to supply every time. A parameter that is not listed is one it may leave out. Most providers do not guarantee that the output matches the schema. You still need server-side checks (see the chapter on validating arguments).
Both choices cost something:
| Choice | What the model tends to do | Typical failure |
|---|---|---|
| Mark a parameter required | Always fills it in | Invents a plausible value when the user never gave one |
| Mark a parameter optional | Includes it only when the conversation supports it | Omits it when it was needed, or sets it needlessly |
So "required" does not mean "important." It means "the tool cannot do anything sensible without this." If the model is pushed to fill a value it does not have, it will guess.
A decision rule
For each parameter, ask three questions in order.
- Can the tool run correctly without it? If not, make it required.
- If it is missing, is there a safe default that the user would expect? If so, make it optional and document the default.
- If it is missing, is "no filter" a meaningful behavior? If so, make it optional and describe what omitting it means.
Apply this to search_orders:
customer_id: without it the search has no scope. Required. The description tells the model to ask the user if it does not know the value, which gives it an alternative to guessing.status: omitting it means "all statuses." Optional.created_after: omitting it means "no date limit." Optional.limit: omitting it means 10. Optional, with the default stated.
Say what omission means
An optional parameter with no stated behavior leaves the model guessing about what leaving it out does. Compare these two descriptions for the same parameter:
{
"status": {
"type": "string",
"enum": ["pending", "shipped", "delivered", "cancelled"],
"description": "Filter by status."
}
}{
"status": {
"type": "string",
"enum": ["pending", "shipped", "delivered", "cancelled"],
"description": "Only return orders with this status. Omit to include all statuses."
}
}The second removes a real ambiguity. With the first, a model asked for "my orders" may pick "pending" because it has to pick something. With the second, it knows that leaving the field out is the correct way to say "all."
The same applies to defaults. Write "Defaults to 10 if omitted" in the description, and then make the server do exactly that. If the description and the code disagree, the model will reason from the description and be wrong about what it gets back.
Let the server own defaults
Do not rely on the model to send default values. It is cheaper and more reliable to apply defaults in your code and keep the schema free of them, or to use default only as documentation. Some providers ignore or reject the default keyword, so the description text is the portable place to state it.
This version of the tool applies the default and checks the one required field. It builds on the {"is_error": ..., "message": ...} result shape used in earlier chapters.
DEFAULT_LIMIT = 10
MAX_LIMIT = 50
VALID_STATUSES = {"pending", "shipped", "delivered", "cancelled"}
ORDERS = [
{"id": "ord_1001", "customer_id": "cus_4821", "status": "shipped", "created_at": "2026-10-02"},
{"id": "ord_1002", "customer_id": "cus_4821", "status": "cancelled", "created_at": "2026-10-15"},
{"id": "ord_1003", "customer_id": "cus_4821", "status": "delivered", "created_at": "2026-09-20"},
]
def search_orders(customer_id=None, status=None, created_after=None, limit=None):
if not customer_id or not isinstance(customer_id, str):
return {
"is_error": True,
"message": (
"customer_id is required and must be a string like 'cus_4821'. "
"Ask the user for their customer ID."
),
}
if status is not None and status not in VALID_STATUSES:
return {
"is_error": True,
"message": f"Invalid status {status!r}. Use one of: {sorted(VALID_STATUSES)}, or omit it.",
}
if limit is None:
limit = DEFAULT_LIMIT
if not isinstance(limit, int) or not 1 <= limit <= MAX_LIMIT:
return {
"is_error": True,
"message": f"limit must be an integer from 1 to {MAX_LIMIT}. Omit it to use {DEFAULT_LIMIT}.",
}
results = [o for o in ORDERS if o["customer_id"] == customer_id]
if status is not None:
results = [o for o in results if o["status"] == status]
if created_after is not None:
results = [o for o in results if o["created_at"] >= created_after]
results.sort(key=lambda o: o["created_at"], reverse=True)
return {"is_error": False, "orders": results[:limit]}
print(search_orders())
print(search_orders(customer_id="cus_4821", status="cancelled"))The first call returns an error that tells the model what to do next. The second applies the default limit and returns the cancelled order. Note that the code treats every parameter as possibly missing, including the required one. Your schema says what the model should send. Your code decides what to accept.
Conditional requirements
Sometimes a parameter is required only when another has a certain value. For example, a refund_order tool needs reason_text only when reason is "other". JSON Schema can express this with oneOf, if/then, or dependentRequired, but provider support is uneven. Some reject these keywords outright, and others accept them without enforcing them.
You have three portable options:
- State the rule in the description: "Required when
reasonisother. Ignore otherwise." - Check the rule on the server and return a clear error when it is broken.
- Split the tool into two tools, each with a flat schema and simple required fields.
Option 3 is the most reliable when the branches are really different operations. Option 1 plus option 2 is the cheapest when they are not.
Optional versus nullable
Some providers' strict modes need every property listed in required. They express "optional" as a type that also allows null, such as {"type": ["string", "null"]}. In that case the model always sends the key, and sends null to mean "not provided."
If you target such an API, apply two rules:
- Say in the description that
nullmeans omitted, for example "Pass null to include all statuses." - Treat
nulland a missing key the same way in your code, asstatus is Nonedoes above.
Check your provider's documentation before relying on this, since the rules change between versions.
Common errors
- Everything required. The model fills fields it has no information for. Look in your logs for values like
"unknown","N/A", or0in fields that should have been left out. - Everything optional. The model calls the tool with an empty object and gets an error. Mark the one or two fields that define the request as required.
- Required field with a default. If the tool works without it, it is not required. Requiring it forces the model to guess.
- Undocumented omission. "Optional" with no stated effect makes the model pick arbitrary values or skip the field at the wrong time.
- Description and code disagree. The description says the default is 10, the code uses 25. The model then misreads results.
- No path to get a missing value. If a field is required and the user may not have it, the description should say to ask the user or which other tool finds it. The
customer_iddescription does this.
Checking your choices
Add test cases to your evaluation set where the user leaves out information. If the prompt says "Show me my orders" without giving a customer ID, the correct behavior is to ask a question and not call the tool with a made-up ID. If the model calls the tool anyway, tighten the customer_id description or add a server error that tells it to ask.
Exercise
A create_ticket tool has parameters title, body, priority (low, normal, high), and assignee_id. If priority is omitted, the server uses "normal". If assignee_id is omitted, the ticket goes to the unassigned queue. Which parameters should be required, and what should the descriptions of the optional ones say?
Show answer
Require title and body, because a ticket cannot be created sensibly without them. Make priority and assignee_id optional. The priority description should say 'Defaults to "normal" if omitted.' The assignee_id description should say 'Omit to leave the ticket unassigned. Use search_users to find an ID.' The server should apply the same defaults and reject invalid values with an error that names the valid options.
Exercise
Your provider's strict mode requires every property to be listed in required. How do you still let the model leave out the status filter?
Show answer
Make the type allow null, for example {"type": ["string", "null"]}. In the description, say that null means "include all statuses." In the server code, treat a null value the same as a missing key.