Skip to main content
Background

Your AI Assistant Can’t Tell “Relevant” From “Allowed”: Miranda Learns to Say No

November 24, 2026 by Alex Leung

Share

Building AI apps on internal data allows you to get fast, accurate answers drawn from your own documents, systems, and records. But these types of apps often face recurring access-control problems when the component that finds the most relevant content is also trusted to decide who is allowed to see it.

Consider an internal assistant that indexes documents from HR, finance, and legal. A question about compensation policy may be semantically closest to an executive compensation plan with restricted access. A similarity score would show that the document is relevant to the question, but that score wouldn’t take into account whether the person asking for it is cleared to read it. If nothing else in the system checks, the restricted document would be shared with someone who’s not meant to see it.

This same gap applies to agents: The action that best fits a request is not necessarily one that the agent is permitted to take. Preventing this gap depends on how the work inside an AI application is divided:

  • A language model interprets the request.
  • An embedding model represents similarity, and a ranking step orders candidates.
  • Metadata supplies authoritative facts such as a document’s classification, and deterministic logic enforces requirements before anything reaches the user.  

Why similarity isn't enough

Each component has a different job, and problems start when one component is asked to do another component’s job. In my previous blog post, What Would RAG Look Like If Miranda Priestly Were the User?, I built Miranda, a visual search system of a catalog of 289,222 fashion images. I explored this distinction between jobs in a new groundedness extension to the search system. One of the lessons I learned from building this was to use a large language model (LLM) only where language reasoning is needed and let simpler components handle the rest, so each part of the system has a clear job and is doing what it’s best at.

Sachidananda Karkala, an Akamai Enterprise Architect, describes a related problem in his post Vector Search Can’t Tell “Yes” from “No”: Semantic similarity alone can’t establish whether a result satisfies a requirement.

To show what that looks like in practice, this post takes Sachidananda’s idea back to Miranda, which I tasked with finding a sweater that’s similar to a request and also meets a hard requirement.

Anatomy of a constrained query: Similarity vs. eligibility

As a reminder, Miranda, the visual search system, uses OpenCLIP to turn images and text into embedding vectors, then uses a single PyTorch matrix multiplication to compare a query against all 289,222 images in the DeepFashion catalog. There’s still no vector database in this experiment.

I started with a simple query: “gray sweater with center zip”

Miranda returned several visually relevant garments. The top result was an Asymmetric Zip-Front Cardigan, with a similarity score of 0.337. The next candidate, a Zippered Crew Neck Sweater, scored 0.329 (Figure 1).

The next candidate, a Zippered Crew Neck Sweater, scored 0.329 (Figure 1).
Fig. 1: The original query produced visual similarity results without a tumble-dry requirement (cardigan 0.337; sweater 0.329)
The next candidate, a Zippered Crew Neck Sweater, scored 0.329 (Figure 1).

Then I added a condition: “gray sweater with center zip, but must be tumble-dryable” (Figure 2).

Then I added a condition: “gray sweater with center zip, but must be tumble-dryable” (Figure 2).
Fig. 2: The constrained query (with synthetic tumble-dry eligibility) leaves 275,787 candidates and excludes 13,435 before final Top-K
Then I added a condition: “gray sweater with center zip, but must be tumble-dryable” (Figure 2).

That second request contains two different questions. “Gray sweater with center zip” is a similarity question: Which garments look and read most like this description? But “Must be tumble-dryable” is a yes-or-no question: Can this particular garment go in a dryer? The first question has a range of good answers. The second has exactly two possible answers for each garment, and only one of those answers makes the garment eligible.

Some parts of a request belong in geometry, as positions in a vector space that can be compared by distance. Others belong in logic, as conditions that are either true or false. Each kind needs its own component, so the sections below follow a request through Miranda’s components in order.

How Miranda processes a constrained search in 4 layers

Miranda processes a constrained search in four layers:

  1. Language layer
  2. Vector and ranking layer
  3. Metadata layer
  4. Deterministic layer

Language layer: Interpreting intent and constraints

The language model’s job is to interpret what the user wants. In my previous post, that meant normalizing Japanese and Italian requests into concise English search intent. A requirement adds a second interpretation task: identifying what kind of condition each part of a request expresses. The language model doesn’t decide whether a given garment qualifies.

I tried several ways a person might talk about drying:

  • “It must be tumble-dryable.”
  • “I need to be able to put it in my dryer occasionally.”
  • “I will never put this garment in the dryer.”
  • “I prefer to dry it in the dryer if possible.”

The first two express a hard requirement. The third tells us dryer compatibility doesn’t matter to this user at all. The fourth is a soft preference, which could reasonably influence ranking without excluding anything. Some requests are ambiguous enough that the right response is a clarifying question.

Sorting a request into hard requirements, soft preferences, exclusions, and points that need clarification is work that requires language reasoning, so it belongs with the LLM. Every later component depends on it. If the language layer fails to recognize that “must be tumble-dryable” is a hard requirement, nothing downstream will enforce it.

Vector and ranking layer: Finding visual matches

The embedding model represents content and queries as vectors, so that items that resemble each other sit close together. OpenCLIP places images and text in a shared vector space, which is why a text query such as “gray sweater with center zip” can be compared directly with photographs of garments.

The ranking step orders candidates by how close they are to the query. In Miranda, that’s the same GeMM operation I described in the first post: one matrix multiplication of the query vector against every image vector, followed by selecting the highest scores.

Together, these two components tell me which garments most resemble the request. In the constrained search’s before-filter diagnostic, the cardigan scores 0.340 against the crew neck’s 0.331, so it ranks higher on visual similarity alone. But neither score says anything about whether either garment can go in a dryer because dryer compatibility isn’t part of how a garment looks. Treating a high similarity score as evidence that a garment is tumble-dryable would be as good as a guess.

Metadata layer: Supplying authoritative facts

To know what’s true about an item, an AI application relies on the metadata layer, which supplies known attributes about each item from an authoritative source. In a real product catalog, that source would be the manufacturer’s care instructions.

Here, I ran into a practical obstacle. DeepFashion is an excellent image dataset, but it doesn’t provide garment-care instructions. I couldn’t ask OpenCLIP whether a cardigan can go into a dryer and treat its similarity score as a care label, and asking an LLM to guess from a photograph wouldn’t solve the grounding problem either.

So, I did something deliberately simple and created synthetic demonstration metadata. In grounding.py, synthetic_tumble_dry_allowed() assigns “False” when an item’s path contains “wool” or “cardigan,” and “True” otherwise. The following excerpt uses the actual function and mask logic from the implementation (with the surrounding validation and return diagnostics omitted):

def synthetic_tumble_dry_allowed(path: str) -> bool:
    """DEMO ONLY: filenames containing ′wool′ or ′cardigan′ are False."""
    name = str(path).lower()
    return not (′wool′ in name or ′cardigan′ in name)

# In apply_tumble_dry_mask(scores, paths, state):
allowed = torch.tensor(
    [synthetic_tumble_dry_allowed(p) for p in paths],
    dtype=torch.bool, device=scores.device,
).unsqueeze(0)
eligible = allowed if state == ′REQUIRED′ else ~allowed
filtered = scores.masked_fill(~eligible, float(′-inf′))

These are synthetic test labels, not real garment-care instructions. Real garments require authoritative care information from the manufacturer. The rule is intentionally artificial, because the experiment is about enforcing a known fact, not discovering textile-care science. It also illustrates a point that applies to any production system: A fact has to exist in the data before anything can enforce it.  

Deterministic layer: Enforcing Boolean rules

Enforcement belongs to the deterministic layer. With 289,222 catalog entries, the synthetic tumble-dry values are converted to a Boolean mask aligned with the similarity scores. For a REQUIRED condition, entries with “False” are ineligible; for a FORBIDDEN condition, the opposite applies.

That’s different from the third drying example above: A user who never uses a dryer hasn’t ruled out tumble-dryable garments, so no mask is applied. The code sets ineligible scores to negative infinity before the final Top-K selection. In the REQUIRED demonstration, this excluded 13,435 entries and left 275,787 eligible entries.

Figure 3 shows what the diagnostic output showed for “gray sweater with center zip, but must be tumble-dryable.”

Figure 3 shows what the diagnostic output showed for “gray sweater with center zip, but must be tumble-dryable.”
Fig. 3: Diagnostic audit for the constrained search: The top-ranked cardigan (0.340) is rejected; the next eligible sweater (0.331) becomes the leading result
Figure 3 shows what the diagnostic output showed for “gray sweater with center zip, but must be tumble-dryable.”

The similarity values in Figure 1 and Figure 3 come from separate query runs and differ slightly. Figure 3 is the controlled before-filter comparison within the constrained run: Applying the mask changes eligibility and final rank, not the underlying similarity scores.

Miranda still finds the same highly similar cardigan. Its embedding didn’t become less similar, and no LLM assigned it a penalty. It was rejected because the metadata marks it ineligible, and a hard requirement is not another similarity score to weigh. A candidate either qualifies or it doesn’t.

This step doesn’t need another LLM call. Once the requirement is represented as a true-or-false check, such as synthetic_tumble_dry_allowed(path) returning “True” for a REQUIRED condition, ordinary software can check it, and the same input produces the same result every time.

Miranda’s division of labor is shown in the table.

Component

Responsibility

LLM

Interpret the user’s natural-language intent

OpenCLIP

Represent visual and textual similarity

PyTorch GeMM

Rank matching catalog entries

Product metadata

Supply known facts about each item

Deterministic constraints

Enforce requirements before presenting results

Miranda’s division of labor

Why one component should never do another component’s job

Each component in Miranda fails when it’s asked to do work that belongs elsewhere.

  • When similarity is treated as eligibility. Without the mask, the cardigan comes back first because it scored highest, even though the user said the garment must be tumble-dryable.
  • When an LLM is asked to establish a fact. Asking a model whether the cardigan in a photo can go in the dryer produces an answer that sounds plausible but has no grounding in care data.
  • When the language layer missed a requirement. If “must be tumble-dryable” is read as a soft preference, the mask is never applied, and the cardigan comes back.
  • When asked for a fact that the data doesn’t contain. Without the synthetic labels, the deterministic layer would have nothing to check, no matter how well every other component performed.

In each case, the output looks reasonable. Miranda outputs a gray sweater with a center zip. The error is only visible if someone checks whether the result met the condition the user stated, which is why exposing intermediate representations, a lesson from the first Miranda post, matters here too.

From garment care to enterprise access control

Now, if you replace the tumble-dry attribute with a security classification, the cardigan becomes the restricted compensation plan from the beginning of this post. The most semantically relevant document is not an eligible answer, and the same division of labor applies: The language layer identifies what’s being asked, similarity finds candidates, an authoritative source supplies each document’s classification and the user’s entitlements, and deterministic logic decides what can be returned.

For action-taking agents, the same distinction holds. The most useful action may still be one the agent isn’t allowed to take, and that permission has to come from policy rather than from relevance.

Because my background is in security, I should add one important difference. In Miranda, the mask is applied after similarity is computed, which is fine because garment metadata isn’t sensitive. Real enterprise authorization must be enforced at an appropriate access boundary, using authoritative identity and policy information, not as a cosmetic filter after confidential data has already been exposed to the model.

The principle is the same one that I explored with the synthetic cardigan metadata: Similarity is not permission, and relevance is not eligibility.

9 questions technical leaders should ask about their own AI architecture

Asking the following nine questions (grouped via Miranda’s five components) offers a practical way to review an AI application before or after deployment:

  • Interpretation
    • Which conditions in our use cases are hard requirements?
    • How does the system distinguish them from preferences?
    • What happens when a request is ambiguous?
  • Similarity and ranking
    • Is a similarity score being used anywhere to decide whether a result is allowed, rather than only how relevant it is?
  • Facts
    • For each hard requirement, where does the authoritative data live?
    • Is the authoritative data available at query time?
  • Enforcement
    • Where is each requirement enforced?
    • For access control, does enforcement happen before data reaches the model, using authoritative identity and policy information?
  • Model use
    • Are we making LLM calls for checks that deterministic logic could perform more predictably?

The division of labor doesn’t change at scale

Miranda is a small experiment, but its architecture has the same jobs as any AI application built on internal data, whether that’s an internal knowledge assistant or a customer-facing agent handling millions of requests. The groundedness implementation and its 10 passing automated tests are available in the feature/minimal-groundedness branch of my GitHub project (commit 5a399ce).

The components get larger and the data more sensitive, but the division of labor doesn’t change: A model interprets the request, similarity finds candidates, authoritative data supplies the facts, and deterministic logic decides what can be returned or done.

What changes with scale is the cost of a component doing the wrong job. In Miranda, it means choosing a cardigan that can’t go in the dryer; in a production system, it can mean that restricted data reaches the wrong person or an agent takes an action it was never authorized to take. That’s why it’s worth deciding early which component does each job, while the system is still small enough to change.

Much of this depends on the language layer correctly identifying what a user is asking for. But there’s another question worth exploring: What if the user doesn’t want to describe a garment in words at all?

Up next: Multimodal search with image-to-image queries

In the next post in this series, I’ll explore how Miranda can accept user-uploaded images and use OpenCLIP’s shared image-text embedding space to find visually similar garments. I’ll also describe how image and text queries can work together, and why adding another modality doesn’t eliminate the need for grounded facts and deterministic constraints. 

Frequently asked questions (FAQ)

Vector search measures semantic or visual similarity, not truth or permission — a document or product can closely match a query while still violating a rule or security policy. Similarly, asking an LLM to guess facts or enforce rules directly introduces unnecessary cost, latency, and hallucination risks. Separating similarity ranking from deterministic rule checks ensures hard requirements are enforced reliably every time.

A reliable architecture splits the workload across specialized layers: a language model interprets user intent and identifies constraints, an embedding model and ranking step find relevant candidates, an authoritative metadata source supplies verified facts (like product specs or user permissions), and deterministic code enforces hard rules before returning results.

Although nonsensitive attributes like product filters can be masked after similarity scoring, enterprise access control must be enforced at an appropriate access boundary before restricted data ever reaches the model. Using authoritative identity and policy checks upstream prevents confidential records from leaking into model context or generated responses.

No. A key job of the language layer is to distinguish between hard requirements (e.g., “must be tumble-dryable”), exclusions, irrelevant details, and soft preferences (e.g., “if possible”). Soft preferences can be used to influence candidate ranking, whereas hard requirements require deterministic Boolean filtering so ineligible items are strictly excluded.

Frequently asked questions (FAQ)

About the author

Alex Leung

Alex Leung

Alex Leung is a Senior Enterprise Architect at Akamai. He advises leading enterprises across media, commerce, and digital platforms on building scalable, secure, and high-performance internet architectures.

With more than 20 years of experience, Alex has led a wide range of initiatives spanning over-the-top (OTT) streaming, edge computing, and large-scale distributed systems. In addition to helping broadcasters evolve their services for OTT delivery, he has conducted security assessments for numerous organizations, strengthening the resilience of their web and mobile applications against modern threats.

Prior to joining Akamai, Alex delivered complex projects including a video-on-demand e-learning platform for government agencies in the Hong Kong SAR  and an image search engine built on Apache SOLR.

He holds a Master’s degree in Applied Physics from Stanford University and a Bachelor’s degree in Engineering Physics from Cornell University.

Tags