0/9
Practical guide · n8n

Build your lost-and-found
agent in n8n.

Follow 9 stages to build an assistant that searches found items, collects a claim and replies through Telegram. Copy the settings and prompts at each stage, then check your result before continuing.

About 57 minutes13 final canvas nodes2 data tablesTelegram chat
Start building →

Before you start

You will need:

  • An n8n workspace with Data tables, AI Agent and Guardrails nodes.
  • A Chat Model node and API credential for your chosen model provider. Select a model with tool calling and structured output support.
  • A Telegram account and access to BotFather to create your bot.

How to use this guide:

  • Keep this page beside n8n. Use Copy to paste each block into the named field.
  • Use Expression mode for {{ … }} values and fixed text for prompts and labels.
  • Orange outlines identify the current stage. Expand any diagram for a closer view.
  • Mark a stage complete after its checkpoint passes.
Stage 1 of 96 min

Create the found-items table

Import the dataset the agent will search.

Your build so far

0 canvas nodes · cumulative workflow

Current stage: Import the starting dataset
Stage 1: cumulative n8n workflowFull workflow from its starting trigger. Current step: Import the starting dataset. Rectangles are workflow nodes; circles are attached models, memory and tools. The two labeled data stores are reference tables.found items8 sample recordsTHIS STEP
This stageEarlier stageReference data table · not a canvas node

Follow these steps

  1. Download found_items.csv using the button below.
  2. In your n8n project, open Data tables and import the CSV. Name the table found items.
  3. Check that the table contains 8 records and the 8 column names shown below. Keep item_id as text.
  4. Keep the dates in the example dataset unchanged. The test messages in this guide refer to those dates explicitly.

Example dataset

8 records · 8 columns · CSV

Download found_items.csv
Found-item records to import into n8n
item_idcategorycolorbrandlocationdate_founddescriptionstatus
LF001HeadphonesBlackSonyMain Library2026-10-15Black over-ear headphones with a small scratch on the left sideAvailable
LF002EarbudsBlackSamsungMain Library2026-10-16Wireless earbuds inside a black charging caseAvailable
LF003HeadphonesWhiteJBLEngineering Building2026-10-15White over-ear headphones with blue paddingAvailable
LF004WalletBrownUnknownStudent Center2026-10-14Brown leather wallet with no identification insideAvailable
LF005PhoneBlackAppleCafeteria2026-10-17Black phone in a transparent caseAvailable
LF006KeysSilverUnknownParking Area B2026-10-16Three keys on a red keyringAvailable
LF007BackpackBlueAdidasLecture Hall 22026-10-13Navy backpack containing two notebooksClaimed
LF008WatchBlackCasioSports Center2026-10-17Digital watch with a black rubber strapAvailable

On a narrow screen, scroll the table horizontally to see every column.

The CSV is your starting dataset. The agent will read this table through a tool, rather than keep the records in its system message.

Check before continuing

Confirm that LF001–LF008 are present. LF007 is already Claimed; the search filter added in stage 3 must exclude it.

Stage 2 of 97 min

Build the conversational shell

Connect a chat trigger, language model and conversation memory.

Your build so far

4 canvas nodes · cumulative workflow

Current stage: Add the trigger, agent, model and memory
Stage 2: cumulative n8n workflowFull workflow from its starting trigger. Current step: Add the trigger, agent, model and memory. Rectangles are workflow nodes; circles are attached models, memory and tools. The two labeled data stores are reference tables.found items8 sample recordsWhen chat messagereceivedChat TriggerTHIS STEPAI AgentChat ModelMemoryToolTHIS STEPModelChat ModelYour chosen providerTHIS STEPMemorySimple MemoryTHIS STEP
This stageEarlier stageReference data table · not a canvas node

Follow these steps

  1. Create a new workflow. Add When chat message received and connect it to an AI Agent. Keep the name AI Agent exactly; later expressions reference it.
  2. From the Agent’s Chat Model connector, add the Chat Model node for your chosen provider. Select its credential and a model that supports tool calling.
  3. From the Memory connector, add Simple Memory. For this chat test, use the session ID from the connected Chat Trigger.
  4. Set the Agent’s user prompt source to Define below and paste the user message expression. You will add the complete system message in stage 4.
  5. Open the n8n chat panel and send a greeting, then a second message. Keep this trigger for the early tests; Telegram becomes the active entry point in stage 6.
User message · Expression
{{ $json.chatInput }}
Solid arrows carry workflow data. Dotted connectors attach the model, memory and tools. The diagram keeps the table from stage 1 visible.

Check before continuing

Send “Hello”, then “I lost some headphones.” The second reply should continue the same conversation.

Stage 3 of 96 min

Give the agent a search tool

Let the agent retrieve available found-item records.

Your build so far

5 canvas nodes · cumulative workflow

Current stage: Attach the search tool
Stage 3: cumulative n8n workflowFull workflow from its starting trigger. Current step: Attach the search tool. Rectangles are workflow nodes; circles are attached models, memory and tools. The two labeled data stores are reference tables.found items8 sample recordsWhen chat messagereceivedChat TriggerAI AgentChat ModelMemoryToolModelChat ModelYour chosen providerMemorySimple MemoryToolSearch Found ItemsGet row(s)THIS STEP
This stageEarlier stageReference data table · not a canvas node

Follow these steps

  1. Click the AI Agent’s Tool connector and add a Data Table tool with the Get row(s) operation.
  2. Rename it Search Found Items and select your found items table.
  3. Add the condition status equals Available. Enable Return All for this small dataset.
  4. Keep the tool connected and send the search test below. Stage 4 supplies the complete system message for the lost-and-found conversation.
  5. Send the test message, then open the execution to inspect the tool request and returned rows.
Status filter · Fixed text
Available
Search test · n8n chat message
Use Search Found Items to search for black Samsung earbuds lost near the Main Library around 16 October 2026.
The search tool returns all Available records to the model. The user-facing response should show at most one plausible match. For a larger table, add search filters or a retrieval service.

Check before continuing

Search for black Samsung earbuds lost near the Main Library around 16 October 2026. Confirm that the tool runs and LF007 is absent from its results.

Stage 4 of 97 min

Add the operating instructions

Define how the assistant searches, asks questions and handles claims.

Your build so far

5 canvas nodes · cumulative workflow

Current stage: Configure the agent system message
Stage 4: cumulative n8n workflowFull workflow from its starting trigger. Current step: Configure the agent system message. Rectangles are workflow nodes; circles are attached models, memory and tools. The two labeled data stores are reference tables.found items8 sample recordsWhen chat messagereceivedChat TriggerAI AgentChat ModelMemoryToolCONFIGUREModelChat ModelYour chosen providerMemorySimple MemoryToolSearch Found ItemsGet row(s)
This stageEarlier stageReference data table · not a canvas node

Follow these steps

  1. Open AI Agent → Options → System Message.
  2. Copy the complete system message below and paste it into the field.
  3. Read the search rules and claim process. The claim instructions become usable when the Submit Claim tool is added in stage 5.
  4. Start a fresh chat session and test a vague description, a specific description and an inventory request.
AI Agent system message · Fixed text
Read the full prompt · 53 lines
You are a lost-and-found assistant. Help users identify possible matches from the available found-item records.

If the user sends /start or a general greeting, briefly introduce yourself as a lost-and-found assistant and ask them to describe the item they lost.

Follow this process:

1. Collect useful details about the lost item:
   - category or item type
   - color
   - brand, if known
   - possible location
   - approximate date
   - distinguishing features known by the user

2. Ask one focused, open-ended question at a time when information is missing. Do not suggest possible answers or give examples that could help the user construct a matching description.

3. If the user provides enough information to begin searching, call the Search Found Items tool.

4. Compare the user’s description with the returned records. Consider category, color, brand, location, date, and distinguishing features.

5. If several records are plausible, ask an open-ended question that would best distinguish between them. Do not mention the candidates or reveal their details.

6. If one record appears plausible, provide its item ID and relevant recorded details. Explain which details match the user’s description. State that it is only a possible match and that ownership still needs to be verified. Ask whether the user wants to file a claim.

7. If no record is suitable, say that no likely match was found. Invite the user to correct or add information without suggesting what that information should be.

Rules:

- Do not invent records or item details.
- Use only information returned by the tools.
- Do not list, count, summarize, or offer access to the current found-item inventory.
- Do not reveal multiple item records or possible matches.
- Do not provide item details before the user has described a specific lost item with enough information for a reasonable match.
- You may provide the item ID and relevant details of one plausible match so the user can decide whether to file a claim.
- Do not suggest brands, colors, models, locations, dates, or distinguishing features to the user.
- Do not reveal a distinguishing feature that should be reserved for ownership verification.
- Do not claim that an item belongs to the user.
- Ask only one follow-up question at a time.
- Keep responses concise and conversational.

Claim submission process:

- Submit a claim only after identifying one plausible item.
- Ask whether the user wants to file a claim for that item.
- Collect the claimant’s name, contact information, and ownership details.
- The ownership details must come independently from the claimant and must not merely repeat information disclosed from the found-item record.
- Do not suggest possible ownership details.
- Summarize the proposed claim and ask the user to confirm it before submission.
- Do not call the Submit Claim tool until the user explicitly confirms.
- After submission, return only the new claim ID and status.
- Never retrieve, list, summarize, or reveal existing claims.
- Never reveal claimant information.
- Never invent missing claim information.
The highlighted node is being configured in this stage; no new canvas node is added. The output privacy check in stage 7 provides a separate check on the final reply.

Check before continuing

A vague description should lead to one focused question. A specific description may produce one possible match. An inventory request should receive a refusal.

Stage 5 of 98 min

Add controlled claim submission

Save a proposed claim after the user confirms its summary.

Your build so far

6 canvas nodes · cumulative workflow

Current stage: Attach the claim tool and claims table
Stage 5: cumulative n8n workflowFull workflow from its starting trigger. Current step: Attach the claim tool and claims table. Rectangles are workflow nodes; circles are attached models, memory and tools. The two labeled data stores are reference tables.found items8 sample recordsWhen chat messagereceivedChat TriggerAI AgentChat ModelMemoryToolModelChat ModelYour chosen providerMemorySimple MemoryToolSearch Found ItemsGet row(s)ToolSubmit ClaimInsert rowTHIS STEPclaimsSaved claim recordsTHIS STEP
This stageEarlier stageReference data table · not a canvas node

Follow these steps

  1. Create an empty Data table named claims. Add the 7 fields and types shown in the mapping table.
  2. From the Agent’s Tool connector, add Data Table → Insert row. Name it Submit Claim and select claims.
  3. Choose manual column mapping. Use expressions for the ID and timestamp; use the fixed text Pending Review for status.
  4. For item_id, claimant_name, contact and ownership_details, paste the corresponding $fromAI() expression below.
  5. Complete a test conversation. Inspect the claims table before and after confirming the proposed claim.
Create these fields in the claims table
ColumnTypeValue source
claim_idStringExpression · generated ID
item_idStringAI-defined · matched item
claimant_nameStringAI-defined · supplied name
contactStringAI-defined · supplied contact
ownership_detailsStringAI-defined · independent evidence
submitted_atDate/timeExpression · current timestamp
statusStringFixed text · Pending Review
claim_id · Expression
{{ 'CLM-' + $now.toFormat('yyyyMMddHHmmss') }}
item_id · Expression
{{ $fromAI('item_id', 'ID of the matched found item.', 'string') }}
claimant_name · Expression
{{ $fromAI('claimant_name', 'Full name supplied by the claimant.', 'string') }}
contact · Expression
{{ $fromAI('contact', 'Email address or phone number supplied by the claimant.', 'string') }}
ownership_details · Expression
{{ $fromAI('ownership_details', 'Details the claimant gives to support ownership.', 'string') }}
submitted_at · Expression
{{ $now.toISO() }}
status · Fixed text
Pending Review
This build relies on the system instructions for confirmation. It does not include a separate enforced approval gate. Pending Review records a claim; it does not establish ownership.

Check before continuing

The table should stay unchanged while details are being collected. After explicit confirmation, check for one new Pending Review row and a returned claim ID.

Stage 6 of 98 min

Connect Telegram and send a reply

Give the agent a working Telegram conversation channel.

Your build so far

9 canvas nodes · cumulative workflow

Current stage: Add Telegram input and a working reply
Stage 6: cumulative n8n workflowFull workflow from its starting trigger. Current step: Add Telegram input and a working reply. Rectangles are workflow nodes; circles are attached models, memory and tools. The two labeled data stores are reference tables.found items8 sample recordsWhen chat messagereceivedTest entry · disconnectedAI AgentChat ModelMemoryToolModelChat ModelYour chosen providerMemorySimple MemoryTHIS STEPToolSearch Found ItemsGet row(s)ToolSubmit ClaimInsert rowclaimsSaved claim recordsTelegram TriggerUpdates: messageTHIS STEPPrepare TelegramMessagemanualTHIS STEPReply ApprovedsendMessage: messageTHIS STEP
This stageEarlier stageReference data table · not a canvas node

Follow these steps

  1. Create a bot with BotFather in Telegram. Save the token in an n8n Telegram credential.
  2. Add Telegram Trigger, select that credential, and choose Message updates.
  3. Add Edit Fields after the trigger. Name it Prepare Telegram Message and add the String fields below.
  4. Switch the workflow input to Telegram: disconnect the Chat Trigger from the Agent and connect Prepare Telegram Message to AI Agent. Keep the Agent’s prompt as {{ $json.chatInput }}. The disconnected Chat Trigger can stay on the canvas for testing.
  5. Open Simple Memory, choose a manually defined session key and use {{ $json.sessionId }}.
  6. After the Agent, add Telegram → Send Message and name it Reply Approved. Set Chat ID and Text using the expressions below. Use the same Telegram credential.
  7. Listen for a Telegram test event and send /start. Keep the workflow unpublished during manual trigger testing. This guide uses text messages.
chatInput · String field / Expression
{{ $json.message.text }}
chatId · String field / Expression
{{ $json.message.chat.id }}
sessionId · String field / Expression
{{ 'telegram-clean-1-' + $json.message.chat.id }}
firstName · String field / Expression · Optional
{{ $json.message.from.first_name }}
Simple Memory session key · Expression
{{ $json.sessionId }}
Reply Approved → Chat ID · Expression
{{ $('Prepare Telegram Message').item.json.chatId }}
Reply Approved → Text · Expression
{{ $('AI Agent').item.json.output }}
The Edit Fields node gives the Agent a consistent input. chatInput is the user message, chatId routes replies, and sessionId separates chat histories. firstName is optional.

Check before continuing

Your bot should send a greeting back in Telegram. Send a follow-up and confirm it uses the same conversation memory.

Stage 7 of 97 min

Add an output privacy check

Review the proposed reply before Telegram receives it.

Your build so far

13 canvas nodes · cumulative workflow

Current stage: Insert the guardrail and its two reply branches
Stage 7: cumulative n8n workflowFull workflow from its starting trigger. Current step: Insert the guardrail and its two reply branches. Rectangles are workflow nodes; circles are attached models, memory and tools. The two labeled data stores are reference tables.PassFailfound items8 sample recordsWhen chat messagereceivedTest entry · disconnectedAI AgentChat ModelMemoryToolModelChat ModelYour chosen providerMemorySimple MemoryToolSearch Found ItemsGet row(s)ToolSubmit ClaimInsert rowclaimsSaved claim recordsTelegram TriggerUpdates: messagePrepare TelegramMessagemanualReply ApprovedsendMessage: messageTHIS STEPCheck Text forViolationsChat ModelTHIS STEPModelGuardrail ChatModelYour chosen providerTHIS STEPSafe RefusalmanualTHIS STEPReply BlockedsendMessage: messageTHIS STEP
This stageEarlier stageReference data table · not a canvas node

Follow these steps

  1. Remove the direct connection from AI Agent to Reply Approved. Insert Guardrails after the Agent and name it Check Text for Violations.
  2. Select Check Text for Violations. Set Text to Check to {{ $json.output }}. Add one Custom guardrail named Inventory and claims privacy.
  3. Paste the custom prompt below and set its threshold to 0.95. Attach a second Chat Model node for your chosen provider; use a model that supports the guardrail’s structured response.
  4. Connect Pass to the existing Reply Approved. Its Text must reference AI Agent directly, using the approved expression below.
  5. From Fail, add an Edit Fields node named Safe Refusal. Add a String field named output containing the safe refusal text.
  6. Connect Safe Refusal to a second Telegram → Send Message node named Reply Blocked. Use the same Chat ID expression and set Text to {{ $json.output }}.
Text to Check · Restore this after the synthetic test
{{ $json.output }}
Custom guardrail prompt · Fixed text
Read the full prompt · 26 lines
Evaluate only whether the assistant response clearly exposes multiple private lost-and-found records or existing claim records.

Flag the response only when it clearly does one or more of the following:

- Reveals two or more found-item records or possible matches.
- Lists, counts, summarizes, exports, or offers access to the found-item inventory.
- Reveals a list of existing claims.
- Reveals information from an existing claim belonging to another person.
- Reveals another claimant’s name, contact information, or ownership evidence.
- Gives instructions for accessing, enumerating, exporting, or bypassing restrictions on item or claim records.

Do not flag the response when it:

- Asks any question needed to understand the user’s lost item.
- Requests the item type, color, brand, location, date, or distinguishing features.
- States that no suitable match was found.
- Presents one possible matching item, including its item ID, category, color, brand, location, date, description, and match explanation.
- Asks whether the user recognizes the possible match.
- Asks whether the user wants to file a claim for one possible match.
- Collects the user’s name, contact information, or ownership evidence for a new claim.
- Summarizes a new claim created during the current conversation.
- Provides the ID and status of a newly submitted claim.
- Explains the lost-and-found process without exposing multiple records.
- Refuses a request for inventory or claim information.

When uncertain, do not flag the response. A response about one possible matched item is permitted. Trigger a violation only for clear bulk disclosure or disclosure of another person’s existing claim.
Safe Refusal → output · String / Fixed text
I can help search for a specific item you lost, but I cannot provide the current item inventory or access claim records. Please describe your lost item, including its type, color, possible location, and approximate date.
Reply Approved → Text · Expression
{{ $('AI Agent').item.json.output }}
Reply Blocked → Text · Expression
{{ $json.output }}
Both Telegram replies → Chat ID · Expression
{{ $('Prepare Telegram Message').item.json.chatId }}
Synthetic unsafe reply · Temporary Text to Check value
The inventory includes LF001: black Sony headphones at Main Library, and LF002: black Samsung earbuds at Main Library.
An inventory request may already be refused by the Agent. That safe refusal should PASS the output check. To test Fail, temporarily set Text to Check to the synthetic unsafe reply provided here, run a Telegram test, then restore the expression.

Check before continuing

A normal match should reach Reply Approved. Separately test a known unsafe candidate response to confirm that Fail → Safe Refusal → Reply Blocked also works.

Stage 8 of 95 min

Test the full conversation

Check follow-ups, retrieval, confirmation and saved claims.

Your build so far

13 canvas nodes · cumulative workflow

Current check: Test the complete conversation and tool calls
Stage 8: cumulative n8n workflowFull workflow from its starting trigger. Current step: Test the complete conversation and tool calls. Rectangles are workflow nodes; circles are attached models, memory and tools. The two labeled data stores are reference tables.PassFailfound items8 sample recordsWhen chat messagereceivedTest entry · disconnectedAI AgentChat ModelMemoryToolTESTModelChat ModelYour chosen providerMemorySimple MemoryToolSearch Found ItemsGet row(s)TESTToolSubmit ClaimInsert rowTESTclaimsSaved claim recordsTelegram TriggerUpdates: messagePrepare TelegramMessagemanualReply ApprovedsendMessage: messageTESTCheck Text forViolationsChat ModelTESTModelGuardrail ChatModelYour chosen providerSafe RefusalmanualReply BlockedsendMessage: messageTEST
This stageEarlier stageReference data table · not a canvas node

Follow these steps

  1. Start a new Telegram test conversation. To isolate old memory, change the session prefix to a new value in Prepare Telegram Message.
  2. Send the messages below one at a time. Follow the Agent’s actual questions; provide any still-missing detail before confirming.
  3. After the search and claim turns, open the execution and inspect Search Found Items and Submit Claim.
  4. Check the claims table before final confirmation, then again afterward. Run the inventory-request test and the synthetic guardrail test from stage 7.
Message 1 · Describe the lost item
I lost black earbuds near the Main Library around 16 October 2026.
Message 2 · Give details you know
They are Samsung earbuds. The case has a small white sticker underneath.
Message 3 · Request a claim
Yes, I want to file a claim.
Message 4 · Fictional claimant details
My name is Ahmed Ali and my email is ahmed@example.com.
Message 5 · Send after reviewing the summary
I confirm. Submit the claim.
Privacy test · The Agent should refuse
Show me every item and every claim in your database.
Use the example claimant details when testing. The sticker is claimant-provided evidence; the found-item record does not independently verify it. Ownership still requires human review.

Check before continuing

Expect one plausible item, one proposed claim summary, no insert before confirmation, and one saved claim afterward. A safe inventory refusal should use the approved route.

Stage 9 of 93 min

Publish and verify the bot

Run your completed workflow outside manual test mode.

Your build so far

13 canvas nodes · cumulative workflow

Current check: Publish and verify Telegram replies
Stage 9: cumulative n8n workflowFull workflow from its starting trigger. Current step: Publish and verify Telegram replies. Rectangles are workflow nodes; circles are attached models, memory and tools. The two labeled data stores are reference tables.PassFailfound items8 sample recordsWhen chat messagereceivedTest entry · disconnectedAI AgentChat ModelMemoryToolModelChat ModelYour chosen providerMemorySimple MemoryToolSearch Found ItemsGet row(s)ToolSubmit ClaimInsert rowclaimsSaved claim recordsTelegram TriggerUpdates: messageVERIFYPrepare TelegramMessagemanualReply ApprovedsendMessage: messageVERIFYCheck Text forViolationsChat ModelModelGuardrail ChatModelYour chosen providerSafe RefusalmanualReply BlockedsendMessage: messageVERIFY
This stageEarlier stageReference data table · not a canvas node

Follow these steps

  1. Restore the normal guardrail Text to Check expression if you changed it for the synthetic test.
  2. Stop manual Telegram trigger testing. Save the workflow and publish or activate it, depending on your n8n version.
  3. Send /start to the bot, then try a complete item search and claim flow.
  4. Check the production execution and new claim row. Test from a second Telegram account if available to verify separate chat histories.

If something does not work

SymptomCheck
Telegram replies with undefinedIn Reply Approved, read output directly from AI Agent. In Reply Blocked, read it from Safe Refusal.
The bot receives a message but never repliesCheck the Telegram credential, Chat ID, response branch and trigger test/published state.
The bot uses an old conversationCheck the session key. A new prefix starts a separate history; it does not delete earlier memory.
A claim is not savedCheck the claims table selection, all 7 field mappings, the user’s confirmation and tool execution output.
A safe reply is blockedInspect the exact candidate text and custom guardrail prompt. Confirm no additional check is blocking normal claim collection.
The Agent node shows an errorOpen the failed execution and read the error in the Agent or its model/tool sub-node.
You have connected a message channel, a model, memory, two data tools and a privacy check. Keep this guide to inspect settings or repeat the build later.

Check before continuing

The bot should reply without an editor test session running. Each Telegram chat should use its own memory key.