From manual queries to AI‑driven agents
For years we typed Lucene queries, checked the syntax, and trusted the response. The new OpenSearch AI agents promise to translate natural language into queries for us, but that convenience can also hide mistakes. An answer that seems right may have been generated from a malformed query or from the wrong index.

Why the illusion happens
The agent builds a query behind the scenes, runs it, and then formats the result. If the query returns zero hits, the agent often fills the gap with a plausible‑sounding paragraph. The output looks successful, yet the underlying data never supported it. Bianca Lewis of OpenSearch points out that "we are not querying like humans anymore" – the AI abstracts the query step, so we lose the visibility that used to protect us.
Symptoms of a hidden mistake
- Too perfect language – the response reads like a polished article, with no qualifiers such as "no results found".
- Missing source references – the agent omits the index name, document IDs, or timestamps that a raw query would normally expose.
- Unexpected totals – the summary claims a count (e.g., "15 incidents") but the underlying
hits.totalis zero or far lower. - Inconsistent timestamps – dates mentioned in the text do not match the
@timestampfield of the returned documents. - Repeated phrasing across unrelated queries – the same boilerplate sentences appear when you ask for different topics.
Auditing the query pipeline
The first line of defence is to log the exact query the agent sends to OpenSearch. Most vendors expose a debug flag or a request interceptor. If the platform does not, you can add a thin proxy that records the HTTP payload.
# Example: simple Node.js proxy that logs incoming OpenSearch requests
const http = require('http');
const { createProxyServer } = require('http-proxy');
const proxy = createProxyServer({ target: 'http://localhost:9200' });
http.createServer((req, res) => {
let body = [];
req.on('data', chunk => body.push(chunk));
req.on('end', () => {
const payload = Buffer.concat(body).toString();
console.log('--- OpenSearch request ---');
console.log(req.method, req.url);
console.log(payload);
// forward the request
proxy.web(req, res);
});
}).listen(9201, () => console.log('Proxy listening on 9201'));
With the raw JSON in hand you can verify:
- Correct index pattern (e.g.,
logs-*vsmetrics-*) - Proper filters and time range
- That
sizeis not set to zero unintentionally
Vendor‑agnostic safeguards
Even if your OpenSearch deployment is managed by a cloud provider, you can add checks that do not rely on proprietary tooling.
- Validate hit count – after the agent returns a summary, query
_countwith the same filter you extracted from the logs. If the count is zero, raise a warning. - Cross‑reference document IDs – embed the first document ID in the agent's answer (e.g., "Document ID: abc123"). A downstream test can fetch that ID and compare fields.
- Time‑window sanity check – compare the earliest and latest timestamps in the result set with the window the user asked for.
- Require explicit provenance – configure the agent to always append a small block like "Source: index=logs‑2024‑11, hits=7" at the end of the answer.
Putting it into practice
Imagine a support dashboard that asks the agent: "How many failed login attempts did we see yesterday?" The answer reads, "We recorded 23 failed logins, most of them from IP 192.0.2.5." Without safeguards you might trust that number. Using the steps above you would:
- Pull the logged query from the proxy – it shows a
rangefilter that ends at "2024‑11‑20T00:00:00Z" instead of the intended "2024‑11‑21". - Run a manual
_countwith the same filter – the result is 0. - Trigger an alert that the agent's answer is based on an empty set.
The dashboard can then surface a message like "No data found for the requested period; the previous answer was generated from a fallback template." This prevents a false sense of security.
Limitations to keep in mind
The approach assumes you have access to the HTTP traffic or can enable logging on the OpenSearch side. In highly restricted environments you may need to work with the security team to add a read‑only audit role. Also, the proxy adds a tiny latency; for real‑time alerting you might prefer a built‑in request interceptor if the vendor provides one.
Takeaway
AI agents make life easier, but they also hide the query step that used to be our safety net. By watching for overly smooth language, logging the generated query, and adding a few sanity checks you can catch the mistakes that look like successes before they cause damage.