Imagine a grower who asks a seed supplier's AI agent what to use against downy mildew on courgette leaves. The agent can reply with advice about watering at the root and thinning the crowded leaves, which is the remedy for powdery mildew, a different disease. The supplier's growing notes cover powdery mildew on courgettes and leave out downy mildew. However, the question has three words in common with the powdery mildew note, so the search returns that note.
The authors of a 2026 benchmark measure what a model does when a tool returns a value that the model cannot use. They call a response dishonest when it asserts a value that the payload cannot support, or when it declines while citing a fabricated limit. Under a deployment-style system prompt, 14.10% of the responses in their benchmark are dishonest. The figure rises to 45.3% when the tool reports success and returns an empty, stale, or truncated value, while one added sentence in the prompt, which asks the model to state a retrieval status before it answers, brings the figure down to 0.87% (arXiv 2609.14758).
Because the model here is a scripted mock, you see the same answers below every time that you execute the files. Swap in a model string when you want a real model to write the wording. Each code block below holds one whole file.
A note with some of the same words
termMatch defaults to any, under which a document matches when it contains any one of the query terms. The analyser drops the stop words what, do, I, for, and on from the grower's question, which leaves five terms. The courgette note contains three of those terms, so it matches.
import { createNarsil } from '@delali/narsil'
import { ToolLoopAgent, tool } from 'ai'
import { z } from 'zod'
import { type GrowingNote, growingModel, QUESTION } from './mock-model.ts'
const narsil = await createNarsil()
await narsil.createIndex('growing_notes', {
schema: { crop: 'enum', section: 'string', advice: 'string' },
language: 'english',
})
await narsil.insertBatch('growing_notes', [
{
id: 'courgette-powdery-mildew',
crop: 'courgette',
section: 'Powdery mildew on courgettes',
advice:
'Powdery mildew shows as a white dust on courgette leaves from midsummer. Water at the root in the morning, thin the crowded leaves for airflow, and pick the fruit young so the plant keeps growing.',
},
{
id: 'tomato-blight',
crop: 'tomato',
section: 'Late blight on tomatoes',
advice:
'Late blight browns the tomato leaf from the tip and blackens the stem within days. Lift and burn the affected plants, keep the remaining foliage dry, and sow a blight-resistant variety next season.',
},
{
id: 'broad-bean-rust',
crop: 'broad bean',
section: 'Chocolate spot on broad beans',
advice:
'Chocolate spot marks broad bean leaves with brown flecks in a wet spring. Space the rows wider, stake the plants upright, and harvest the lower pods first.',
},
{
id: 'carrot-fly',
crop: 'carrot',
section: 'Carrot fly',
advice:
'Carrot fly larvae tunnel into the root and leave rusty scars. Sow after the first flight in June, cover the bed with fine mesh, and sow thinly so that no thinning releases the scent.',
},
])
const growingTools = {
searchNotes: tool({
description: 'Search the growing notes by what their text says.',
inputSchema: z.object({ text: z.string() }),
execute: async ({ text }: { text: string }): Promise<GrowingNote[]> => {
const found = await narsil.query<GrowingNote>('growing_notes', {
term: text,
document: { include: ['section', 'advice'] },
limit: 1,
})
return found.hits.map((hit) => hit.document)
},
}),
}
const askGrowingAgent = async (): Promise<string> => {
const agent = new ToolLoopAgent({
model: growingModel(),
instructions: 'Answer the grower from the growing notes.',
tools: growingTools,
})
const reply = await agent.generate({ prompt: QUESTION })
return reply.text
}
console.log(JSON.stringify({ question: QUESTION, growerHeard: await askGrowingAgent() }, null, 2))
await narsil.shutdown(){
"question": "What do I use for downy mildew on courgette leaves?",
"growerHeard": "Powdery mildew shows as a white dust on courgette leaves from midsummer. Water at the root in the morning, thin the crowded leaves for airflow, and pick the fruit young so the plant keeps growing. That comes from the 'Powdery mildew on courgettes' note."
}The grower receives advice from the supplier's notes, in the supplier's wording, for the wrong disease. The answer looks like a full match, because the tool drops the score before it returns the note.
WhatdoIusefordownymildewoncourgetteleaves?
Require every term, and watch what the model does with an empty result
Under termMatch: 'all', a document matches only when it contains every query term. Because no note contains the word downy, the strict query matches nothing. suggest with the prefix 'down' also returns an empty list, because no term in the index starts with those letters.
With nothing matched, the tool returns an empty array, so the model answers from its training data about mildew.
import { createNarsil } from '@delali/narsil'
import { ToolLoopAgent, tool } from 'ai'
import { z } from 'zod'
import { type GrowingNote, growingModel, QUESTION } from './mock-model.ts'
const narsil = await createNarsil()
await narsil.createIndex('growing_notes', {
schema: { crop: 'enum', section: 'string', advice: 'string' },
language: 'english',
})
await narsil.insertBatch('growing_notes', [
{
id: 'courgette-powdery-mildew',
crop: 'courgette',
section: 'Powdery mildew on courgettes',
advice:
'Powdery mildew shows as a white dust on courgette leaves from midsummer. Water at the root in the morning, thin the crowded leaves for airflow, and pick the fruit young so the plant keeps growing.',
},
{
id: 'tomato-blight',
crop: 'tomato',
section: 'Late blight on tomatoes',
advice:
'Late blight browns the tomato leaf from the tip and blackens the stem within days. Lift and burn the affected plants, keep the remaining foliage dry, and sow a blight-resistant variety next season.',
},
{
id: 'broad-bean-rust',
crop: 'broad bean',
section: 'Chocolate spot on broad beans',
advice:
'Chocolate spot marks broad bean leaves with brown flecks in a wet spring. Space the rows wider, stake the plants upright, and harvest the lower pods first.',
},
{
id: 'carrot-fly',
crop: 'carrot',
section: 'Carrot fly',
advice:
'Carrot fly larvae tunnel into the root and leave rusty scars. Sow after the first flight in June, cover the bed with fine mesh, and sow thinly so that no thinning releases the scent.',
},
])
const growingTools = {
searchNotes: tool({
description: 'Search the growing notes by what their text says.',
inputSchema: z.object({ text: z.string() }),
execute: async ({ text }: { text: string }): Promise<GrowingNote[]> => {
const found = await narsil.query<GrowingNote>('growing_notes', {
term: text,
termMatch: 'all',
document: { include: ['section', 'advice'] },
limit: 1,
})
return found.hits.map((hit) => hit.document)
},
}),
}
const askGrowingAgent = async (): Promise<string> => {
const agent = new ToolLoopAgent({
model: growingModel(),
instructions: 'Answer the grower from the growing notes.',
tools: growingTools,
})
const reply = await agent.generate({ prompt: QUESTION })
return reply.text
}
console.log(JSON.stringify({ question: QUESTION, growerHeard: await askGrowingAgent() }, null, 2))
await narsil.shutdown(){
"question": "What do I use for downy mildew on courgette leaves?",
"growerHeard": "Spray a copper-based fungicide every ten days and remove the worst leaves as you go."
}The answer leaves out the wrong note; however, it is worse than before. A copper fungicide is plausible advice for a mildew, but the supplier publishes no such advice. A grower who follows it will therefore follow a recommendation that appears in none of the supplier's notes. The tool reports success while it returns nothing usable, which is the case in which the authors above measure 45.3%.
Return a status, and the nearest note with it
The instruction to the model gains one sentence, which asks the model to open its answer with retrievalStatus. The authors lower dishonesty from 14.10% to 0.87% with a sentence of the same kind. The tool sets that field from the result of the strict query, so only your code chooses its value.
preflight counts the documents that a loose query matches, without building any hits. When that count is above zero, the tool fetches the nearest note. When the count is zero, the tool returns the status alone, so the model can tell the grower only that the notes contain nothing on that disease.
import { createNarsil } from '@delali/narsil'
import { ToolLoopAgent, tool } from 'ai'
import { z } from 'zod'
import { type GrowingNote, growingModel, QUESTION } from './mock-model.ts'
import { growingModel, type NoteSearch, QUESTION } from './mock-model.ts'
const narsil = await createNarsil()
await narsil.createIndex('growing_notes', {
schema: { crop: 'enum', section: 'string', advice: 'string' },
language: 'english',
})
await narsil.insertBatch('growing_notes', [
{
id: 'courgette-powdery-mildew',
crop: 'courgette',
section: 'Powdery mildew on courgettes',
advice:
'Powdery mildew shows as a white dust on courgette leaves from midsummer. Water at the root in the morning, thin the crowded leaves for airflow, and pick the fruit young so the plant keeps growing.',
},
{
id: 'tomato-blight',
crop: 'tomato',
section: 'Late blight on tomatoes',
advice:
'Late blight browns the tomato leaf from the tip and blackens the stem within days. Lift and burn the affected plants, keep the remaining foliage dry, and sow a blight-resistant variety next season.',
},
{
id: 'broad-bean-rust',
crop: 'broad bean',
section: 'Chocolate spot on broad beans',
advice:
'Chocolate spot marks broad bean leaves with brown flecks in a wet spring. Space the rows wider, stake the plants upright, and harvest the lower pods first.',
},
{
id: 'carrot-fly',
crop: 'carrot',
section: 'Carrot fly',
advice:
'Carrot fly larvae tunnel into the root and leave rusty scars. Sow after the first flight in June, cover the bed with fine mesh, and sow thinly so that no thinning releases the scent.',
},
])
const growingTools = {
searchNotes: tool({
description: 'Search the growing notes by what their text says.',
inputSchema: z.object({ text: z.string() }),
execute: async ({ text }: { text: string }): Promise<GrowingNote[]> => {
const found = await narsil.query<GrowingNote>('growing_notes', {
execute: async ({ text }: { text: string }): Promise<NoteSearch> => {
const matched = await narsil.query<{ section: string; advice: string }>('growing_notes', {
term: text,
termMatch: 'all',
document: { include: ['section', 'advice'] },
limit: 1,
})
return found.hits.map((hit) => hit.document)
if (matched.hits.length > 0) {
return { retrievalStatus: 'matched', notes: matched.hits.map((hit) => hit.document) }
}
const loose = await narsil.preflight('growing_notes', { term: text })
if (loose.count === 0) return { retrievalStatus: 'nothing matched', notes: [] }
const nearest = await narsil.query<{ section: string }>('growing_notes', {
term: text,
document: { include: ['section'] },
limit: 1,
})
return {
retrievalStatus: 'nothing matched',
notes: [],
nearest: { section: nearest.hits[0].document.section, looseMatches: loose.count },
}
},
}),
}
const askGrowingAgent = async (): Promise<string> => {
const agent = new ToolLoopAgent({
model: growingModel(),
instructions: 'Answer the grower from the growing notes.',
instructions:
'Answer the grower from the growing notes, and open the answer with the retrievalStatus that the tool returned.',
tools: growingTools,
})
const reply = await agent.generate({ prompt: QUESTION })
return reply.text
}
console.log(JSON.stringify({ question: QUESTION, growerHeard: await askGrowingAgent() }, null, 2))
await narsil.shutdown(){
"question": "What do I use for downy mildew on courgette leaves?",
"growerHeard": "retrievalStatus: nothing matched. No note covers downy mildew on courgettes, and the nearest of 3 partial matches is 'Powdery mildew on courgettes', which is a different disease."
}With the status in the answer, the grower learns that the notes contain nothing on their disease, that three notes have some of the same words, and that the nearest of them is about a different disease. REMEMBERED_TREATMENT is still in the mock; however, the mock answers from the status, so the answer leaves that treatment out.
You can also set minScore, although a floor on the score is harder to choose. The engine ranks with BM25, whose scores have no fixed upper bound, so a floor of 2.0 that suits this index and this question can reject every hit on another index or another question. Measure the scores on your index before you set a floor. When a match depends only on which words a note contains, use termMatch.
Where to go next
- Read Full-text search for
termMatch,minScore, the typo tolerance, andsuggest. - Read Search by wording and by meaning for a question whose words appear in no note, which keyword search can't match under any term policy.
- Read Cite the passage behind an answer for how to attach a reference to each hit that the tool returns.