An n8n workflow that takes a US location and a code type, then returns the currently adopted building code, the adopting authority, the state administrative-code reference, any local amendments, and 3–6 official sources.
The workflow uses an OpenAI function-calling agent (GPT-4o) with the Serper Google Search API as a tool. A separate GPT-4o-mini call resolves ambiguous location strings ("Renton WA", a ZIP code, a full street address) into a canonical "City, State" jurisdiction before the agent runs.
- User Input Form — n8n form trigger collects
LocationandCode Type. - Validate Input — code node enforces length (3–200 chars) and allowed code-type values.
- Resolve City & State — GPT-4o-mini (temperature 0) resolves the raw location into
City, Full State Name, or returnsUNKNOWN. - Parse City/State — falls back to the raw location if resolution returns
UNKNOWN. - Build Agent Prompt — composes the research brief for the agent.
- Building Code Research Agent — GPT-4o agent that calls the
web_searchtool (Serper) up to 5 times following a deliberate search strategy (city ordinance → state administrative code → local amendments). - Structured Output Parser — enforces the JSON schema for downstream rendering.
- Format HTML Output — code node escapes user content and renders a safe HTML summary.
- Show Results to User — n8n form completion page displays the formatted summary.
| Field | Type | Notes |
|---|---|---|
Location |
text (required) | City + State, ZIP, or full address. Example: Renton WA, 98168, 4414 S 144th St. |
Code Type |
dropdown (required) | One of: Building Code, Residential Code, Fire Code, Mechanical Code, Plumbing Code, Electrical Code. |
The agent returns JSON conforming to:
{
"executive_summary": "2–3 sentence overview of the current code status.",
"base_code": "e.g., 2021 Uniform Plumbing Code",
"adopting_authority": "e.g., Washington State Building Code Council",
"state_code_reference": "e.g., Chapter 51-56 WAC",
"local_amendments": "Summary of city-specific amendments, or 'None found'.",
"results": [
{
"title": "...",
"link": "https://...",
"snippet": "...",
"source_type": "city | state | publisher | other"
}
]
}The results array contains 3–6 official sources, prioritized in this order: official municipal / .gov / .us domains → recognized publishers (codepublishing.com, municode.com, ecode360.com, iccsafe.org) → state agency PDFs.
Two n8n credentials are required.
OpenAI — already wired up in the workflow under the name OpenAi account. Open the Resolve City & State and OpenAI Chat Model (GPT-4o) nodes and confirm the credential is selected.
Serper API — create a new credential in n8n:
- Type: HTTP Header Auth
- Name:
Serper API - Header name:
X-API-KEY - Header value: your Serper API key (get one at serper.dev)
Then open the Web Search Tool (Serper) node and select the Serper API credential. The exported workflow has REPLACE_WITH_SERPER_CREDENTIAL_ID as a placeholder until you do this.
- Open your n8n instance.
- Workflows → Import from File → upload
AI-Powered Building Code Lookup.json. - After import, open the two OpenAI-backed nodes and the Serper node and verify credentials are attached.
- Activate the workflow.
Open the form URL exposed by the User Input Form node (path: building-code-finder), fill in a location and code type, and submit. The result page renders inline.
| Step | Model | Why |
|---|---|---|
| City/state resolution | gpt-4o-mini (temp 0) |
Cheap, deterministic geocoding. |
| Research agent | gpt-4o (temp 0.1) |
Function-calling support and reliable grounding. |
| Web search tool | Serper (google.serper.dev/search) |
Up to 5 calls per run; agent decides when to stop. |
- The agent node (
@n8n/n8n-nodes-langchain.agent) is required for tool calling — attaching tools to a plain LLM completion node leaves them uninvoked. - The Structured Output Parser is wired as the agent's
ai_outputParser, so the HTML node always receives the expected shape. - The HTML formatter escapes all user/AI strings and validates URLs against
^https?://before rendering, to keep the form completion page safe from injection. - The agent system prompt forbids fabricated URLs — every link in the output must come from a
web_searchtool result in that run.
AI-Powered Building Code Lookup.json— the n8n workflow export.User_Instructions.md— end-user guide for running the form.Outbrief_Session.md— session debrief and next-step recommendations.
© 2026 Greyfibre Developer Network | Prepared by Bilal Haider
