ExamplescriptintermediateRunnableresearch-brief
Web Search
Runnable example (intermediate) for script using docling, openai.
Key Facts
- Level
- intermediate
- Runtime
- Python • OpenAI API
- Pattern
- Context-backed research with explicit evidence
- Interaction
- Live sandbox • Script
- Updated
- 14 March 2026
Navigate this example
Library
Browse examplesReopen the wider library to compare adjacent patterns and linked learning paths.Interaction
Run sandbox nowTry the interaction directly in this example’s guided sandbox surface.Source
Open full sourceRead the real implementation, highlighted checkpoints, and runtime requirements.MCP
Call via MCPUse the same resource inside agents, deterministic exports, and MCP setup flows.
Linked principles
2-web-search.py
python
from typing import List
from openai import OpenAI
from pydantic import BaseModel
client = OpenAI()
MODEL = "gpt-5-nano" # use a reasoning model for better performance
# --------------------------------------------------------------
# Define the output model
# --------------------------------------------------------------
class Citation(BaseModel):
text: str
url: str
class SearchResult(BaseModel):
answer: str
citations: List[Citation]
# --------------------------------------------------------------
# Configure domain restrictions
# --------------------------------------------------------------
domains = [
"rijksoverheid.nl",
"tweedekamer.nl",
"cbs.nl",
]
# --------------------------------------------------------------
# Perform web search with domain filtering
# --------------------------------------------------------------
query = "What are the current policies and regulations regarding AI implementation in Dutch government services, and what are the key requirements for public sector AI adoption?"
response = client.responses.parse(
model=MODEL,
reasoning={"effort": "medium"},
tools=[
{
"type": "web_search",
"filters": {
"allowed_domains": domains,
},
}
],
tool_choice="auto",
include=["web_search_call.action.sources"],
input=query,
instructions="You are a policy research assistant for Dutch governmental agencies. You search official government websites to find relevant policy documents, regulations, and official information. For each piece of information in your answer, provide a citation that includes the specific text excerpt and the URL where it came from. Make sure to answer in English.",
text_format=SearchResult,
)
result = response.output[-1].content[-1].parsed
print(result.model_dump_json(indent=2))
print(result.answer)
Related principles
- P4trustApply progressive disclosure to system agencyProvide the minimum information necessary by default, while enabling users to inspect additional detail when confidence, understanding, or intervention is required.Open principle →
- P6visibilityExpose meaningful operational state, not internal complexityPresent the state of the system in language and structures that are relevant to the user, rather than exposing low-level internals that do not support action or understanding.Open principle →
- P7trustEstablish trust through inspectabilityUsers should be able to examine how a result was produced when confidence, accountability, or decision quality is important.Open principle →
- P9orchestrationRepresent delegated work as a system, not merely as a conversationWhere work involves multiple steps, agents, dependencies, or concurrent activities, it should be represented as a structured system rather than solely as a message stream.Open principle →