Skip to content
AgentLabs.

Function-Calling Agents: Designing Clear Function Schemas

Function-Calling Agents: Designing Clear Function Schemas

Function-calling agents: writing function schemas that reduce errors without losing your head

Anyone working with language models knows this moment all too well: you invest, refine, build an intelligent agent, connect functions and define parameters. Then the AI agent chooses the wrong function, supplies half-missing parameters or uses a format resembling an old National Insurance form. Not because it is stupid, but because your function schema left too much room for guesswork.

In other words, having an agent is no longer enough. You need to design function schemas that respect both the model and developers. This is part art, part engineering and part psychological understanding of how a language model thinks about calling a function.

Why do function schemas matter, and what does that mean for a modern AI agent?

Had we spoken two years ago, most AI discussion would have concerned free text: questions and answers, writing and summarisation. Today, the discussion is shifting towards getting an AI agent to act as well as talk: call APIs, activate systems, arrange meetings, book flights, launch an advertising campaign or retrieve data from BI systems.

This is where function calling comes in. Instead of merely suggesting what to do, the model calls real functions in your code. Each function is wrapped in a schema: a formal description of what it does, its parameters, each parameter's type and which are required or optional. Simple on paper. In practice, this is where many AI agents fail.

I have seen quite a few systems where the agent knew what to do and even described it correctly in text, but the schema was vague enough to make it choose the wrong function, send a string where an array was expected or simply omit a required field. Then comes the guessing cycle: a code fix, another prompt, another patch, more examples. Often, the problem actually lies one step earlier, in the design of the function schemas themselves.

The common mistake: treating a function schema as dry documentation

In classic development, we write a function signature, perhaps add a comment and move on. The compiler, type system or at least the IDE protects us. With an AI agent, the schema must also serve as machine documentation. It is more than a definition. It is the language in which you tell the model how to call the function.

Here is the point people tend to miss: the model reads the schema as text. Yes, it understands JSON and types, but words too. If the schema is too dry, brief or unclear, it leaves room for interpretation. Where interpretation exists, an AI agent follows statistical probability rather than developer intent. A small difference, but painful in production.

A function schema as a product specification, beyond a function signature

Think of a good function schema as a UX specification for an agent. You are writing more than get_user(id: string). You explain: “This function retrieves user details using an internal system identifier, rather than an email address or telephone number. Do not use it if you have only a first name.” This looks less like code and more like a specification. Intentionally so.

Once function schemas are understood as a communication layer between person and model, rather than simply a formal compiler specification, the whole approach to AI agent design changes.

How do you build good schemas? Principles emerging from practice

Let us leave theory aside. On the ground, Israeli organisations using AI agents in real banking, healthcare, SaaS and small start-up systems keep discovering similar errors. The solutions are similar too. Here are several recurring principles, offered as insights rather than iron laws.

1. Function names that tell a story, beyond a utility

An AI agent does not see the code; it sees the function name and description. With functions named get_data or update, do not be surprised if the model gets confused. The name is the model's first signal: “When may I use this?”

Instead of get_user, prefer:

get_user_by_internal_id

Or even:

get_crm_user_by_internal_id

It is longer, but much clearer to the model whether it needs this function or another, such as find_user_by_email. This verbal distinction dramatically reduces errors, particularly when the agent has dozens of functions available.

2. Precise verbal descriptions: models read the small print too

Through laziness or time pressure, many developers write terse descriptions: “Get user”, “Update task”, “Search items”. Seemingly enough. In practice, a recipe for inaccuracy.

A good schema description should answer basic questions:

  • In which context is this function used?
  • What does it not do?
  • Are there similar functions, and how do they differ?
  • What counts as good input?

The AI agent reads this text like documentation. A few good descriptive lines can eliminate an enormous amount of trial and error in practice.

3. Parameters: less “perhaps”, more clarity about what is required

The natural tendency when defining schemas is to add optional parameters just in case. Perhaps we will need them later; perhaps they will sometimes be convenient. The problem is that an AI agent sees an optional field and thinks, if we briefly anthropomorphise it, “If it's optional, I can skip it.” Particularly when the information is not explicitly in the user's question.

The practical advice is not to make a parameter optional merely because it might not always be available. If your system cannot work without that field, require the model to supply it too, or explain how the agent should obtain it, for example through another function.

Ideally, an AI agent should not need to guess which parameters are truly required. The schema itself makes that unambiguous.

4. Do not hesitate to include examples in description fields

One less discussed but highly effective trick is putting small examples directly into the schema.

{
  "name": "create_support_ticket",
  "description": "Creates a new enquiry in the support system. Use this function only when the user asks to open a new ticket, rather than update an existing one. Example: 'Open a ticket for my login problem.'",
  ...
}

Models imitate examples. Show an agent what counts as an appropriate function trigger and it follows that pattern. The same applies to specific parameters: typical values, date formats and identifier structures. One short example inside a schema can save dozens of incorrect calls.

When the AI agent phenomenon meets Israeli bureaucracy

There is something distinctive about working with AI agents in Israel. On one hand, start-ups casually treating an agent as another microservice. On the other, large organisations, regulators and core systems from two decades ago.

In large organisations, fields such as mispar_eshkol or kod_misrad are part of life. They matter greatly to the system, but are completely unreadable to people as well as models. Function schemas become perhaps even more critical here: effectively a translation layer between organisational language and agent language.

Speak to an AI agent in human language, rather than legacy-system language

Instead of defining a parameter named kod_misrad without explanation, you could write:

{
  "name": "kod_misrad",
  "description": "The office's internal code as it appears in the legacy system. If the user does not have the code, do not guess; use the 'search_office_by_name' function to find it.",
  "type": "string"
}

Notice the sentence: “Do not guess; use the 'search_office_by_name' function.” This is precisely where proper communication between functions, through good schemas, prevents disorder. The AI agent receives a behavioural cue: what to do instead of inventing a value.

Organisations taking this seriously discover a new language in the middle: more than a technical API, it is a shared working protocol between product professionals, developers and the agent.

Classic function schema mistakes that get agents into trouble

You could write a book about common mistakes alone. Let us examine several that genuinely keep recurring.

One field doing two jobs

For example, one parameter named query used for free-text search, identifier filtering and sometimes date parsing. To the model, query is query. The AI agent will not always independently understand which mode you expect.

Separate them instead: free_text, user_id and date_range. The model is strong at inference, but should not be forced to guess your mode every time. Splitting parameters also increases the chance of discovering errors during development, rather than when the agent is already speaking to customers.

Conflicting descriptions between a function and its fields

This has happened more than once: a function is defined as returning transactions in a particular month, while the date field says “Start date for a free transaction search”. The model reads both, does not always know which takes precedence and sometimes follows field descriptions rather than the function's general description.

Consistency between the general description and field descriptions is more than aesthetics. It is a guidance mechanism. An AI agent tends to trust the most recent and detailed text it sees.

Too many functions doing approximately the same thing

Another pattern: a product requirement changes weekly, and each time a new function appears: search_users, advanced_search_users, search_users_by_segment, search_users_new… Sometimes convenient for development. A nightmare for an AI agent.

The model must decide which function to use. When differences are subtle and poorly described, it chooses according to word statistics rather than product intent. In practice, one flexible function with clear parameters and a good explanation of use cases is preferable to four near-identical functions.

Combining prompting and schemas to reduce errors

You cannot discuss function-calling agents without the relationship between the general prompt and schemas. They are not separate worlds. On the contrary, a good prompt tells the agent how to treat functions, while schemas provide detailed explanations as needed.

Say explicitly: “If you are unsure, do not fake it”

The main prompt defining an AI agent's character has room for clear instructions such as:

Whenever you consider calling a function, check whether you have all essential parameters as defined in the schema. If information is missing, do not assume it from memory or guess. Ask the user a clarifying question, or use a function that helps obtain the missing information.

This sounds almost trivial, but without such sentences a model sometimes prefers to manage with what it has: supplying a default value, inventing a location or rounding a date. Combining prompt guidance with rich schemas produces an agent described as careful rather than delusional.

A complete conversation example, beyond an isolated schema

Organisations successfully building stable AI agents work extensively with end-to-end examples. Beyond what the function looks like, they show a dialogue where the agent decides to call it, with which parameters and what it does with the response.

These examples can be retained as internal documentation or even added to the model's instructions. The model does more than see the schema; it learns appropriate usage patterns.

Table: key function schema tips for AI agents

TopicCommon problemRecommended function schema approachEffect on the AI agent
Function namesGeneric names such as get_data or updateSpecific, distinct names, such as get_crm_user_by_internal_idLess confusion between similar functions and more appropriate usage
Function descriptionsShort, unclear descriptionsExplain when to use it, when not to and differences from other functionsFewer incorrect calls and more accurate function selection
Required and optional parametersExcessive optional fields added because they might be neededRequire only genuinely critical fields; explain how to obtain missing informationLess model guessing and more predictable behaviour
Field namesUnreadable internal namesRetain the technical name with a rich, clear description in HebrewThe agent better understands field meaning, including in legacy systems
Usage examplesSchemas without examplesAdd example trigger sentences, formats and valuesThe model imitates correct patterns and reduces problematic variations
Function countMany similar functions with similar namesCombine into one flexible function with clear parametersSimpler decisions and fewer function-selection errors
Description consistencyContradictions between function and parameter descriptionsCheck complete alignment between all schema partsPrevents textual confusion when the model calls a function
Prompt integrationA general prompt that does not address function-calling behaviourExplicit instructions on careful use, clarification and avoiding guessesA more cautious AI agent inventing fewer missing data items

Frequently asked questions about function-calling agents and function schemas

Are long descriptions really necessary for every function?

Not compulsory, but they pay for themselves. In small systems with two or three functions, brief descriptions may suffice. Once an AI agent works with ten, twenty or fifty functions, descriptions become working tools rather than decoration. The model does not experience text overload as we do; it actually enjoys it.

How many functions are too many for one AI agent?

There is no magic number, but a principle: the more overlapping functions, the harder selection becomes. If the agent works with a large number, say more than 30–40 different functions, ensure names and descriptions are highly distinct, or consider dividing it into smaller agents, each with clear responsibilities. Often, narrowing intelligence's operating space actually produces more intelligence.

Should you protect the server side or trust the agent?

The honest answer is always to protect the server side. Good function schemas reduce errors but do not replace real validation. The model may send an ID not belonging to the current user, or a date outside an allowed range. Your system must check this conventionally, as with any API. The AI agent is an important participant, but it is neither the source of truth nor a security mechanism.

What if there is an important field users almost never provide?

This requires process design. Instead of making the field optional and trusting the AI agent to manage, give it a way to obtain the information: a function converting an email address to an ID, or one receiving a company name and returning an internal identifier. The main function's schema can explicitly state, “If this field is missing, use function X first to obtain it.”

How can you test your schemas without going straight into production?

Technically, the simplest approach is to build a sandbox, run real scenarios and check which functions the agent uses along the way, as well as whether it reaches the solution. Patterns such as calling the wrong function before correcting itself, or trying to send unnecessary values, indicate that the schemas do not yet communicate clearly enough. Manually review several conversations too, asking, “If I were a new developer on the team, would I understand what this function does from its schema alone?” If the answer is “Not really”, it is difficult for the model too.

How this meets everyday development work in Israel

At the most practical level, function schemas are becoming part of product specification. No longer a separate, purely technical document. Teams taking AI agents seriously begin including agent specifications in the PRD alongside features and user UX specifications: which functions will exist, how they differ, how they will be described and how the model should choose between them.

A subtle cultural change is occurring too. Product professionals learn to write language the model understands, developers learn to formulate descriptions and documentation, that word suggesting a tedious chore, suddenly becomes part of the business core. An AI agent does not suffer from long documentation. It depends on it.

Looking ahead: schemas as part of every AI agent's identity

We can imagine, in the not-too-distant future, function schemas undergoing evolutionary development themselves: systems automatically suggesting description improvements, comparing real usage with definitions and flagging where the model repeatedly struggles. In other words, the agent will help us repair the language in which we speak to it.

Until this happens automatically, the work remains ours: precise names, descriptions slightly longer than feels comfortable, a willingness to add examples and an understanding that each schema is more than another boring JSON object. It is part of a working agreement between person and AI agent.

A brief conclusion and an invitation to talk

When discussing function-calling agents today, we are really discussing a language model trying to fit into a real world: systems, APIs, decade-old data, impatient users and product managers changing requirements. Good function schemas allow all this to work without breaking.

Those treating schemas as a technical item soon discover their agent doing too many foolish things. Those treating them as a communication layer discover a more stable, predictable AI agent that can be trusted in significant processes, beyond peripheral chats.

If you are considering introducing an AI agent into your product, or have begun and are struggling with functions and schemas, we would be happy to help with an initial consultation at no cost: analysing the architecture together and finding where proper function schema design can reduce errors and save months of trial and error.

From reading to a pilot

Choose which systems to connect to the pilot

We will assess which data the agent needs to read, which actions it should propose and where the outcome is recorded.