Web Search and File Reading: Who Should Handle Tool Execution in LLM Applications
Adding web search and file reading to an LLM application is more than wiring up a function call. This article walks through the full tool execution pipeline—searching, fetching pages, extracting content, and managing context—and compares two execution paths: client-side orchestration and server-side tools. It also covers why models don't always call declared tools, how to verify that answers are actually grounded in external sources, how to prepare files for model consumption, and practical recommendations for shipping reliable tool-augmented applications.
Web Search and File Reading: Who Should Handle Tool Execution
Web Search and File Reading Are More Than One Extra Function
Many developers, when first adding web search to a model, treat it as adding a single function call. In practice, the search itself is only the first step. Calling the search service, requesting web pages, handling redirects and timeouts, extracting the main content, stripping out navigation and ads, compressing the text, and putting the results back into the conversation context—every one of these steps can fail, and each consumes time and context window space.
Consider a common scenario: an assistant needs to help a reader compare the update notes of two versions of a product. The user provides a link to the official release page and asks what problems this update resolved. This involves at least three steps: reading the page, judging whether the page content is sufficient to answer the question, and, if necessary, searching for additional material. This scenario is used only to illustrate the workflow and does not represent any benchmark results.
Two Execution Paths
1. Client-Side Orchestration
The application itself decides every action. It parses the user’s message, requests the web page, handles download failures and content extraction, and then hands the organized material to the model. If the model requests a follow-up query, the application calls the search API, receives the results, and proceeds to the next round of reasoning. The model is responsible for judgment; the application is responsible for making the tools actually run.
This approach offers the strongest control. Query terms, timeout policies, retry rules, caching, and deduplication are all decided by the developer. The cost is more complex state management—any failure anywhere in the loop needs a fallback.
2. Server-Side Tools
The developer declares the allowed capabilities in the request, and the server performs tool execution and result injection. The client no longer shuttles search results back and forth; it only handles the final answer and tool events. The model’s judgment and the tool’s execution remain two separate stages—the change is that the intermediate plumbing moves to the server side.
If your application needs to specify query terms itself and only wants search results or page content without the model’s conversation loop, you can call standalone search and fetching capabilities directly.
3. How to Choose: Who Controls the Flow
The decision criterion boils down to one question: who controls the process. If the task steps are relatively fixed—for example, “read and summarize whatever link the user provides”—and you have strict requirements on data sources, client-side orchestration is more controllable. If the task is open-ended and you want the model to decide what to search and how many times, server-side tools can significantly reduce boilerplate code.
Declaring a Tool Doesn’t Mean the Model Will Always Call It
Enabling web search only means the model is capable of calling it. Whether to search, and which link to read, is still decided by the model based on the question. Keep the following points in mind:
- Understand the difference between tool declaration and invocation policy. Some server-side tools cannot be forced to execute; forcing the setting may cause the request to be rejected. When tool choice is disabled, these tools are usually disabled as well. The specific rules depend on your platform’s documentation.
- For scenarios where you only need to read a specified link, declare only the reading tool. This prevents the model from launching unrelated searches, reducing both cost and the risk of drifting off-topic.
- With reasoning mode enabled, the model may search, open pages, and look up sections repeatedly across multiple inference steps. Multi-step workflows provide opportunities for further verification, but more verification does not mean a correct conclusion. The model can still misread pages or cite inappropriately, so checks at the application layer are still needed.
How to Confirm the Answer Is Actually Grounded in External Sources
A UI badge saying “web search enabled” only means the capability is available—it does not prove the answer was based on retrieved data. Your application should combine three types of signals:
- Tool events: whether there are records of search or fetch actions, along with their parameters and return statuses.
- Citations: whether the key conclusions in the answer can be mapped to specific sources and passages.
- Source quality: whether the source is accessible, whether it is a primary source, and whether its publication date is relevant to the question.
Never mark an answer as verified based solely on a confident tone. One practical approach: display a “Verified” label only when both a successful tool event and a valid citation exist; otherwise, display “Unverified.”
Here is illustrative code. Field names are placeholders—replace them with the actual response structure of your platform.
# Illustrative code: shows the verification logic onlydef verify_answer(response):events = response.get("tool_events", [])citations = response.get("citations", [])succeeded = [e for e in events if e.get("status") == "success"]if not succeeded:return "not_retrieved"if not citations:return "retrieved_but_no_citations"return "verified"
File Reading: Turn Files into Usable Material First
Handing a file directly to a model does not guarantee the model reads meaningful information. Files must first be converted to text before entering the context, typically through these steps:
- Type detection: choose a parser based on the format—plain text, documents, spreadsheets, presentations, or images.
- Text extraction: extract the body content. Plain text can be read directly; structured documents require preserving heading hierarchy, paragraphs, and table boundaries.
- Layout analysis and OCR: scanned documents and images require optical character recognition. Complex layouts such as multi-column formatting, headers and footers, and chart annotations need layout analysis, or the reading order will be scrambled.
- Chunking and filtering: split long documents by chapter or fixed length, remove repeated headers, tables of contents, and irrelevant appendices, and keep page numbers or position information for each chunk to support later citations.
- Context budgeting: allocate material space according to the model’s context length. Too much material crowds out instructions and conversation history; too little omits key information.
Parsing quality directly determines answer quality. Sample-check the extraction results after parsing, especially numbers and formulas in tables—these are the most error-prone during conversion.
Practical Recommendations
- First decide whether the task actually needs external information. Questions answerable from a local knowledge base don’t need web search.
- Set timeouts, retry limits, and failure messages for every tool, so a single network glitch doesn’t derail an entire conversation turn.
- Log tool events and citations for auditing and troubleshooting.
- For factual content such as prices, policies, and release notes, maintain a source whitelist or priority list.
- Run regression tests with a fixed sample set covering three cases: questions that need no retrieval, questions that need retrieval, and broken links—verifying your application’s behavior on each branch.
