AI Application Development: Architecture, Tools, and Security
A practical breakdown of AI application development: the five-layer architecture, function calling, structured outputs, and OWASP's LLM security risks.

AI application development means building software with a dedicated layer for model inference, tool and data access, and output validation — not just calling a chatbot API from inside an existing web app. That extra layer is what lets a model safely read your data, call your systems, and return output your code can trust, rather than just producing a chat reply.
Searches for how to build an AI app usually land on vendor-neutral checklists that skip the actual mechanics. This piece grounds each step — architecture, tool calling, structured output, and security — in the primary documentation that defines it, from OpenAI, Anthropic, and Microsoft's own engineering guidance.
What Makes AI Application Development Different From an API Call
Microsoft's Azure Well-Architected Framework draws a useful line here. An inferencing application performs a single-step operation — classification, translation, summarization — and its architecture is correspondingly simple: a client talks to an AI gateway that handles authentication, quotas, safety, and routing, and that gateway calls a model-serving layer. Results can be cached before they reach the client. There's no agent, no multi-step reasoning, no tool-calling loop.
An intelligent application is a different shape of problem. Here, the client invokes an agent or agent orchestrator, which plans across multiple steps, decides which tools to call, and may reach into grounding knowledge services such as a search index or database along the way. Models can get invoked more than once in a single user interaction, and caching can happen at several points in that chain.
The distinction matters because it decides how much architecture you actually need. If your product need is answering “classify this support ticket,” you may not need an agent framework at all — you need a well-designed inferencing pipeline. If it's “triage this support ticket, look up the customer's order history, and draft a response,” you're building an intelligent application. Before committing to either path, it's worth scoping which one you're actually building — custom AI development usually starts with exactly that question, and that's what our guide to AI MVP development walks through in more detail.
The Five Architectural Layers an AI Application Needs
Microsoft's framework breaks an AI application into five layers, each with its own policies, identities, and caching strategy:
- Client layer — the UI or client application where users experience the AI feature. Kept thin; most logic lives elsewhere.
- Intelligence layer — routing, orchestration, and agent capabilities: model routing, conversation management, and decision-making.
- Inferencing layer — runs the trained model itself: loading, input preprocessing, output postprocessing, and serving predictions via an API.
- Knowledge layer — grounding data, knowledge graphs, and retrieval services that give the intelligence layer context, while enforcing data access policies.
- Tools layer — the business APIs and external services the intelligence layer can invoke, each using standardized interfaces and enforcing its own security.
Three recommendations from that framework are worth internalizing before you write any code. First, keep intelligence away from the client: back-end services, not client code, should handle rate limiting, failover, and AI processing logic, so behavior can change without touching every client. Second, block direct access to data stores: AI code shouldn't query your database directly — route it through an API that enforces authorization and carries the user's identity into retrieval and filtering. Third, abstract your models and tools behind standardized interfaces, so you can swap a model or a tool provider later without rewriting the application around it.
This layering is also where agent orchestration lives for a business-process use case — if you're weighing whether to build that orchestration yourself or lean on an existing agent pattern, our overview of AI agents for business covers the trade-offs.
Connecting the Model to Your Systems: Function Calling, Step by Step
Once you've decided your application needs an intelligence layer that can act — not just answer — you need a way for the model to reach your systems. OpenAI calls this function calling (also “tool calling”), and it works as a five-step loop:
- You send the model a request along with a list of tools it could call.
- The model responds with a tool call — the name of a tool and the arguments it wants to use.
- Your application executes code on its own side, using the input from that tool call.
- You send a second request to the model, this time including the tool's output.
- The model returns a final response, or issues another tool call if it needs more information.
A “function” in this scheme is a specific kind of tool defined by a JSON schema — your code gets structured input it can parse and act on. OpenAI also supports custom tools that work with free-form text instead of a schema, and built-in tools that let the model search the web, run code, or reach an MCP server. If your application ends up with a large number of available functions, OpenAI's guidance is to pair function calling with tool search, which defers rarely used tools and loads them only when the model actually needs them — though this specific capability is limited to GPT-5.4 and later models, so check your model's support before architecting around it.
The practical upshot for an architecture built around the five layers above: the tool call lands in your intelligence layer, gets executed against your tools layer (or knowledge layer, for a lookup), and the result flows back up to the model. None of that logic should live in the client.
Client Tools vs. Server Tools: Where the Code Actually Runs
Anthropic's documentation for Claude frames the same idea slightly differently, and the distinction is useful regardless of which model you're calling: tools differ primarily by where the code runs.
Client tools — both the tools you define yourself and Anthropic-defined schema tools like bash and text_editor — run inside your application. When Claude wants to use one, it responds with stop_reason: “tool_use” and one or more tool_use blocks; your code then executes the operation and sends the result back as a tool_result block, continuing the conversation.
Server tools — web_search, web_fetch, code_execution, and tool_search — run on Anthropic's own infrastructure instead. You get the results directly in the response, without writing or hosting any execution logic yourself, unless Claude calls a server tool in the same batch of parallel calls as one of your client tools.
Either way, a tool you define needs a name, a description, and an input_schema, so the model knows what it's for and what arguments to supply. Deciding which tools should be client-side versus relying on server tools is itself an architecture decision: server tools reduce what you have to build and operate, but client tools are what let the model reach data and systems that are specific to your business — your CRM, your order database, your internal APIs. Most real applications end up using both.
Getting the Model to Return Data You Can Actually Use
Function calling solves how a model reaches your systems. Structured Outputs solves a related but different problem: getting the model's final answer back in a shape your code can parse without guesswork.
Structured Outputs constrains a completed, non-refusal model response to a JSON Schema you supply. Your application still has to handle refusals, incomplete responses, and API errors itself, and still has to validate any business rule the schema doesn't express — schema conformance isn't the same as business-logic correctness. OpenAI offers Structured Outputs in two forms: through function calling (for when the model is calling a tool), or through a json_schema response format (for when the model is replying directly to the user in a specific shape).
It's worth being precise about where this sits relative to JSON mode, the earlier mechanism for getting JSON out of these models. Both approaches produce syntactically valid JSON; only Structured Outputs guarantees the output actually matches your schema — required fields present, enum values honored. OpenAI recommends using Structured Outputs instead of JSON mode wherever possible, though Structured Outputs via the json_schema response format is only supported starting with the gpt-4o-mini, gpt-4o-mini-2024-07-18, and gpt-4o-2024-08-06 model snapshots and later — worth checking against whatever model you're targeting before you commit an architecture to it.
For an application built around a layered design, this is where the inferencing layer's output postprocessing step gets a lot simpler: instead of writing a brittle parser to coax structure out of free text, you define the schema once and the model's output already conforms to it.
The Security Risks You're Signing Up For
None of the above is complete without accounting for what can go wrong. OWASP's Top 10 for LLM Applications (2025) names ten risk categories specific to building with large language models, on top of the security practices that apply to any application:
- LLM01: Prompt Injection — user-supplied or retrieved content alters the model's intended behavior.
- LLM02: Sensitive Information Disclosure — the model or application exposes data that shouldn't be exposed.
- LLM03: Supply Chain — vulnerabilities introduced through the models, training data, plugins, or dependencies your application relies on.
- LLM04: Data and Model Poisoning — pre-training, fine-tuning, or embedding data gets manipulated to introduce vulnerabilities.
- LLM05: Improper Output Handling — insufficient validation or sanitization of what the model outputs before it's used downstream.
- LLM06: Excessive Agency — the system is granted more autonomy, permissions, or functionality than the task actually requires.
- LLM07: System Prompt Leakage — the instructions meant to stay internal to the system get exposed.
- LLM08: Vector and Embedding Weaknesses — risks specific to how vectors and embeddings are generated, stored, and retrieved.
- LLM09: Misinformation — the model produces false or misleading information presented as fact.
- LLM10: Unbounded Consumption — the application allows excessive, uncontrolled resource or model usage.
This list isn't exhaustive — it's OWASP's named 2025 set, not the full universe of risks an AI application can carry, and it doesn't replace traditional application security. But it's a useful checklist to run against your own design: Excessive Agency and Improper Output Handling, in particular, map directly onto the function-calling and tool-use patterns above. A tool that lets the model delete records or send emails without a human or policy check in between is excessive agency by definition, no matter how well the function-calling flow itself is implemented.
Designing So the Application Survives Model and Vendor Changes
The five-layer architecture, the tool-calling mechanics, and the OWASP risk list all assume you'll be maintaining this application after the model you built it on gets updated, deprecated, or replaced. Two habits from Microsoft's framework make that maintenance less painful.
The first is treating prompts as externalized, version-controlled configuration, in the spirit of the Twelve-Factor App principles, rather than hardcoding prompt text into application logic. Keeping prompts in version control with clear deployment tracking means you can correlate a behavior change, or a safety incident, with the exact prompt version that was live when it happened, and roll back a prompt the same way you'd roll back a bad deploy.
The second is building in observability from day one rather than bolting it on later: tracking model performance (accuracy drift, inference latency, confidence scores) and monitoring data quality (shifts in the input data your model sees) as first-class signals, not an afterthought once something has already broken in production.
Put together, the five-layer separation, the externalized prompts, and the observability give you an application that can survive a model swap, a pricing change, or a provider outage without a rewrite — which, over the life of a production AI feature, is usually what determines whether it's still running a year later. If you're weighing whether to build this yourself or bring in a team that's already built the layering, the tool integrations, and the guardrails, that's exactly the gap our AI web application development service is built to close.
If you want help scoping or building one of these, talk to our team.
Frequently asked questions
What's the difference between function calling and Structured Outputs?
Function calling connects the model to your systems — it's how the model requests that your code execute an action or fetch data, following OpenAI's five-step tool-calling flow. Structured Outputs instead shapes what the model says back to the user or your application, constraining its final response to a JSON Schema you supply. OpenAI supports Structured Outputs through function calling or through a separate json_schema response format, so the two aren't mutually exclusive.
What's the difference between a client tool and a server tool?
A client tool runs inside your own application: the model returns a tool_use block, and your code executes the operation and sends back a tool_result. A server tool — such as web_search, web_fetch, code_execution, or tool_search in Anthropic's implementation — runs on the provider's own infrastructure instead, so you receive the result directly without hosting any execution logic yourself.
Should AI processing logic run in the browser or the backend?
Microsoft's Azure Well-Architected Framework recommends keeping the client layer thin and delegating AI processing logic, rate limiting, and failover handling to back-end services. Running that logic in the browser exposes it to the end user and makes it harder to apply consistent authorization, quotas, and safety controls across every client.
What security risks are specific to AI applications that traditional app security doesn't cover?
OWASP's Top 10 for LLM Applications (2025) names risks that don't have a direct equivalent in traditional application security, including Prompt Injection, Excessive Agency, System Prompt Leakage, and Vector and Embedding Weaknesses. These sit on top of — not instead of — ordinary web application security practices, since an AI application still has a traditional attack surface as well.
What's the difference between an “inferencing” application and an “intelligent” application?
An inferencing application performs a single-step operation like classification or summarization, typically through a simple client-to-gateway-to-model pipeline. An intelligent application performs multi-step planning and coordination through an agent or agent orchestrator, which can call a tools layer and grounding knowledge services, and often invokes the model more than once per user interaction.