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.
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.
Create the found-items table
Import the dataset the agent will search.
Your build so far
0 canvas nodes · cumulative workflow
Follow these steps
- Download
found_items.csvusing the button below. - In your n8n project, open Data tables and import the CSV. Name the table
found items. - Check that the table contains 8 records and the 8 column names shown below. Keep
item_idas text. - 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
| item_id | category | color | brand | location | date_found | description | status |
|---|---|---|---|---|---|---|---|
| LF001 | Headphones | Black | Sony | Main Library | 2026-10-15 | Black over-ear headphones with a small scratch on the left side | Available |
| LF002 | Earbuds | Black | Samsung | Main Library | 2026-10-16 | Wireless earbuds inside a black charging case | Available |
| LF003 | Headphones | White | JBL | Engineering Building | 2026-10-15 | White over-ear headphones with blue padding | Available |
| LF004 | Wallet | Brown | Unknown | Student Center | 2026-10-14 | Brown leather wallet with no identification inside | Available |
| LF005 | Phone | Black | Apple | Cafeteria | 2026-10-17 | Black phone in a transparent case | Available |
| LF006 | Keys | Silver | Unknown | Parking Area B | 2026-10-16 | Three keys on a red keyring | Available |
| LF007 | Backpack | Blue | Adidas | Lecture Hall 2 | 2026-10-13 | Navy backpack containing two notebooks | Claimed |
| LF008 | Watch | Black | Casio | Sports Center | 2026-10-17 | Digital watch with a black rubber strap | Available |
On a narrow screen, scroll the table horizontally to see every column.
Check before continuing
Confirm that LF001–LF008 are present. LF007 is already Claimed; the search filter added in stage 3 must exclude it.
Build the conversational shell
Connect a chat trigger, language model and conversation memory.
Your build so far
4 canvas nodes · cumulative workflow
Follow these steps
- Create a new workflow. Add
When chat message receivedand connect it to anAI Agent. Keep the nameAI Agentexactly; later expressions reference it. - 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.
- From the Memory connector, add
Simple Memory. For this chat test, use the session ID from the connected Chat Trigger. - 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.
- 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.
{{ $json.chatInput }}Check before continuing
Send “Hello”, then “I lost some headphones.” The second reply should continue the same conversation.
Give the agent a search tool
Let the agent retrieve available found-item records.
Your build so far
5 canvas nodes · cumulative workflow
Follow these steps
- Click the AI Agent’s Tool connector and add a Data Table tool with the Get row(s) operation.
- Rename it
Search Found Itemsand select yourfound itemstable. - Add the condition
statusequalsAvailable. Enable Return All for this small dataset. - Keep the tool connected and send the search test below. Stage 4 supplies the complete system message for the lost-and-found conversation.
- Send the test message, then open the execution to inspect the tool request and returned rows.
Available
Use Search Found Items to search for black Samsung earbuds lost near the Main Library around 16 October 2026.
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.
Add the operating instructions
Define how the assistant searches, asks questions and handles claims.
Your build so far
5 canvas nodes · cumulative workflow
Follow these steps
- Open AI Agent → Options → System Message.
- Copy the complete system message below and paste it into the field.
- Read the search rules and claim process. The claim instructions become usable when the Submit Claim tool is added in stage 5.
- Start a fresh chat session and test a vague description, a specific description and an inventory request.
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.
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.
Add controlled claim submission
Save a proposed claim after the user confirms its summary.
Your build so far
6 canvas nodes · cumulative workflow
Follow these steps
- Create an empty Data table named
claims. Add the 7 fields and types shown in the mapping table. - From the Agent’s Tool connector, add Data Table → Insert row. Name it
Submit Claimand selectclaims. - Choose manual column mapping. Use expressions for the ID and timestamp; use the fixed text
Pending Reviewfor status. - For
item_id,claimant_name,contactandownership_details, paste the corresponding$fromAI()expression below. - Complete a test conversation. Inspect the claims table before and after confirming the proposed claim.
| Column | Type | Value source |
|---|---|---|
claim_id | String | Expression · generated ID |
item_id | String | AI-defined · matched item |
claimant_name | String | AI-defined · supplied name |
contact | String | AI-defined · supplied contact |
ownership_details | String | AI-defined · independent evidence |
submitted_at | Date/time | Expression · current timestamp |
status | String | Fixed text · Pending Review |
{{ 'CLM-' + $now.toFormat('yyyyMMddHHmmss') }}{{ $fromAI('item_id', 'ID of the matched found item.', 'string') }}{{ $fromAI('claimant_name', 'Full name supplied by the claimant.', 'string') }}{{ $fromAI('contact', 'Email address or phone number supplied by the claimant.', 'string') }}{{ $fromAI('ownership_details', 'Details the claimant gives to support ownership.', 'string') }}{{ $now.toISO() }}Pending Review
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.
Connect Telegram and send a reply
Give the agent a working Telegram conversation channel.
Your build so far
9 canvas nodes · cumulative workflow
Follow these steps
- Create a bot with BotFather in Telegram. Save the token in an n8n Telegram credential.
- Add
Telegram Trigger, select that credential, and choose Message updates. - Add Edit Fields after the trigger. Name it
Prepare Telegram Messageand add the String fields below. - Switch the workflow input to Telegram: disconnect the Chat Trigger from the Agent and connect
Prepare Telegram MessagetoAI Agent. Keep the Agent’s prompt as{{ $json.chatInput }}. The disconnected Chat Trigger can stay on the canvas for testing. - Open Simple Memory, choose a manually defined session key and use
{{ $json.sessionId }}. - 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. - Listen for a Telegram test event and send
/start. Keep the workflow unpublished during manual trigger testing. This guide uses text messages.
{{ $json.message.text }}{{ $json.message.chat.id }}{{ 'telegram-clean-1-' + $json.message.chat.id }}{{ $json.message.from.first_name }}{{ $json.sessionId }}{{ $('Prepare Telegram Message').item.json.chatId }}{{ $('AI Agent').item.json.output }}Check before continuing
Your bot should send a greeting back in Telegram. Send a follow-up and confirm it uses the same conversation memory.
Add an output privacy check
Review the proposed reply before Telegram receives it.
Your build so far
13 canvas nodes · cumulative workflow
Follow these steps
- Remove the direct connection from
AI AgenttoReply Approved. Insert Guardrails after the Agent and name itCheck Text for Violations. - Select Check Text for Violations. Set Text to Check to
{{ $json.output }}. Add one Custom guardrail namedInventory and claims privacy. - 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. - Connect Pass to the existing
Reply Approved. Its Text must referenceAI Agentdirectly, using the approved expression below. - From Fail, add an Edit Fields node named
Safe Refusal. Add a String field namedoutputcontaining the safe refusal text. - Connect
Safe Refusalto a second Telegram → Send Message node namedReply Blocked. Use the same Chat ID expression and set Text to{{ $json.output }}.
{{ $json.output }}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.
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.
{{ $('AI Agent').item.json.output }}{{ $json.output }}{{ $('Prepare Telegram Message').item.json.chatId }}The inventory includes LF001: black Sony headphones at Main Library, and LF002: black Samsung earbuds at Main Library.
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.
Test the full conversation
Check follow-ups, retrieval, confirmation and saved claims.
Your build so far
13 canvas nodes · cumulative workflow
Follow these steps
- Start a new Telegram test conversation. To isolate old memory, change the session prefix to a new value in Prepare Telegram Message.
- Send the messages below one at a time. Follow the Agent’s actual questions; provide any still-missing detail before confirming.
- After the search and claim turns, open the execution and inspect Search Found Items and Submit Claim.
- Check the claims table before final confirmation, then again afterward. Run the inventory-request test and the synthetic guardrail test from stage 7.
I lost black earbuds near the Main Library around 16 October 2026.
They are Samsung earbuds. The case has a small white sticker underneath.
Yes, I want to file a claim.
My name is Ahmed Ali and my email is ahmed@example.com.
I confirm. Submit the claim.
Show me every item and every claim in your database.
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.
Publish and verify the bot
Run your completed workflow outside manual test mode.
Your build so far
13 canvas nodes · cumulative workflow
Follow these steps
- Restore the normal guardrail Text to Check expression if you changed it for the synthetic test.
- Stop manual Telegram trigger testing. Save the workflow and publish or activate it, depending on your n8n version.
- Send
/startto the bot, then try a complete item search and claim flow. - 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
| Symptom | Check |
|---|---|
| Telegram replies with undefined | In Reply Approved, read output directly from AI Agent. In Reply Blocked, read it from Safe Refusal. |
| The bot receives a message but never replies | Check the Telegram credential, Chat ID, response branch and trigger test/published state. |
| The bot uses an old conversation | Check the session key. A new prefix starts a separate history; it does not delete earlier memory. |
| A claim is not saved | Check the claims table selection, all 7 field mappings, the user’s confirmation and tool execution output. |
| A safe reply is blocked | Inspect the exact candidate text and custom guardrail prompt. Confirm no additional check is blocking normal claim collection. |
| The Agent node shows an error | Open the failed execution and read the error in the Agent or its model/tool sub-node. |
Check before continuing
The bot should reply without an editor test session running. Each Telegram chat should use its own memory key.