# Design Explanations for Recommendations

> How to design the why behind a recommendation so it is true, useful and easy to check, explained simply for your AI interview.

**In short:** Show the real reason a recommendation was made, taken from the signals the system logged, and say when a business rule moved the item. A reason written after the fact can sound right and still be wrong.

AI and LLM interview question Q362, LLM system design. Intermediate, occasional (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/design-explanations-for-recommendations

## Say it in 30 seconds

When a recommender suggests an item, I build the reason from the signals it actually used: past orders, similar parts, or a promotion that moved the item up. I save those reasons while the system runs, and the text reads from that log. I don't ask a model to invent a reason afterwards, because it can sound right and still be wrong. The user should also see when a rule changed the order.

## Say it in 2 minutes

A recommender picks items for a person, and each pick should come with a true reason. My rule is that the reason must match what the system actually did. If the line says "because you bought this before" but the item rose because of a discount, the user has been told something false, even when each part of the line sounds fine.

The system works in stages. It gathers candidates, a ranker scores them, and then re-ranking rules move or drop items. So I save the reasons at each stage as it runs, and I build the text from that saved log. A language model can also write an explanation after the decision. That text can sound fine while nothing checks it against the ranking. NIST, the US standards body, says explainability (how well a system can show its reasons) can answer how a decision was made in the system, so the record has to be real.

I write the explanation for the reader. A parts planner needs one clear line, and an auditor needs the log entry behind it. Then I test. Each week I sample recommendations and check that every reason shown appears in the log for that item. If a rule moved an item, the line must say so. A check like this takes a short time to run, and it catches a wrong line before a buyer does.

## What is a recommendation explanation, in plain words?

A recommender is software that picks items for a person. On a plant's reorder page, it decides which spare parts appear first. Google's machine learning course says recommendation models work by "analyzing similarities between items and past user interactions to suggest relevant content". A recommendation explanation is the short line beside an item that says why it was picked, such as "Ordered 4 times by your plant this year."

Picture a senior buyer at a spare-parts store. A site manager asks why she stocked a gate valve. She pulls up the orders and the sales that led to it. A good explanation works the same way: it points to the records the system really used.

- **Candidate:** An item the system thinks might fit, before the final order is set.
- **Ranker:** The model that gives each candidate a score.
- **Re-ranking rule:** A rule that moves, boosts or drops items after scoring, such as a discount or a stock check.
- **Post-hoc explanation:** A reason worked out or written after the decision, rather than built into the model.
- **Logged reason:** A reason the system saves while it runs, so it can be checked later.

## How does a recommendation get its reason?

Most recommenders work in stages. Google's course says "Candidate generation is the first stage of recommendation." Given a query, the system builds a set of relevant candidates. One common way is content-based filtering, which recommends items similar to what the user likes. A second common way is collaborative filtering, which uses similarity between users and items. Its example is simple: if user A is like user B, and user B likes a video, the system can suggest that video to user A.

Next, the ranker scores the candidates. Last come the re-ranking rules. The course describes that final stage as "In the final stage of a recommendation system, the system can re-rank the candidates to consider additional criteria or constraints." That is where a discount or a stock check changes the order, and where an explanation can drift from the truth.

*Diagram, Where the reason comes from: Two signals feed the ranker, which scores the candidates. Re-ranking rules can then move or drop items. The reason shown is built from the log of all of it, so the text matches what happened.*
1. Past orders go to the ranker, which scores each candidate.
2. Similar parts go to the ranker as well.
3. The scored list then passes through the re-ranking rules.
4. The reason shown is built from what the log saved.

A worked case, with made-up numbers. A plant's reorder list covers 180,000 part numbers. For a 6204 bearing, the ranker sees four orders from this plant in the past year, so the score is high. For a 2-inch gate valve, it sees similar parts the team saved, so the score is medium. Then a supplier discount is set to end on Friday, and the promo rule moves the valve to the top. The line for the valve must name the discount, not only the saved parts. "Moved up: a supplier discount ends Friday." tells the truth about both.

## Where should the reason come from?

There are two ways to write the line. The first reads the reasons the system saved while it ran. The second asks a language model to write a reason after the decision. NIST says that "Explainability can answer the question of "how" a decision was made in the system." So the first way is the one that can be checked.

- **Read from the log: Matches what happened.** The text is built from the reason codes the system saved. It can only say what those codes record, so the codes must be true to how the ranker works.
- **Written after: Sounds right, may be wrong.** A model writes a believable story from the item and the question. Nothing checks it against the ranking.

*Diagram, Two ways to write the reason: A logged reason can be checked line by line against the record. A model's story can sound right while the real cause is something else.*
1. The text is read from the saved codes, so it matches the record only if the codes are true.
2. The model writes a reason with no record behind it.

A survey of explainable recommendation says explanations may be post-hoc or come from a model built to be read. It also says explanations help transparency and trust, and help designers debug the system. NIST adds that explainable systems can be debugged and monitored more easily.

> "Explainable recommendation tries to address the problem of why: by providing explanations to users or system designers, it helps humans to understand why certain items are recommended by the algorithm" (Survey on explainable recommendation (arXiv))
>
> "Risk from lack of explainability may be managed by describing how AI systems function, with descriptions tailored to individual differences such as the user's role, knowledge, and skill level." (NIST AI Risk Management Framework)

So one reason can come at two depths: one clear line for a planner, and the full log entry for an auditor.

> **Tip:** Asked to design this? Say the reasons come from logs, name any rule that moved an item, and tailor the depth to who reads it. Don't promise that the model knows its own mind.

## How do you check that a reason is true?

Test the text, not the model's mood. For a sample of recommendations, compare each line shown with the log for that item. Here is a small made-up version. The text is built only from logged codes, and a rule that moved an item always appears in the line.

1. **Log every reason:** Save the reason codes, and any rule that changed the order, at the moment of the decision.
2. **Build the text from the log:** Each line is a lookup from a logged code. Nothing is written freely.
3. **Sample and compare:** Each week, pull a random set of recommendations and check every line against its log.
4. **Re-check after changes:** After a model update or a new rule, run the same check again, because old wording can stop matching.

```python
# A made-up reorder list for a plant. Each reason text comes only from
# the reasons the ranker logged, so the line can't name a cause it never used.
LOG = [
    {"item": "6204 bearing", "reasons": ["ordered_4x"], "rule": None},
    {"item": "2-inch gate valve", "reasons": ["similar_saved"], "rule": "promo_ends_friday"},
]
TEXT = {
    "ordered_4x": "Ordered 4 times by your plant this year.",
    "similar_saved": "Similar to parts your team saved.",
    "promo_ends_friday": "Moved up: a supplier discount ends Friday.",
}

def explain(entry):
    lines = [TEXT[code] for code in entry["reasons"]]
    if entry["rule"]:
        # A rule that moved the item must be named, never hidden.
        lines.append(TEXT[entry["rule"]])
    return " ".join(lines)

for entry in LOG:
    print(entry["item"] + ": " + explain(entry))
```

Output:

```text
6204 bearing: Ordered 4 times by your plant this year.
2-inch gate valve: Similar to parts your team saved. Moved up: a supplier discount ends Friday.
```

NIST notes that explainable systems can be debugged and monitored more easily, and that they lend themselves to more thorough documentation, audit and governance. That is why the log is worth the storage.

### How would you explain recommendations to a buyer who doesn't trust them?

Start with the buyer's question, not the model. A buyer who has been caught by a wrong suggestion wants two answers: did the system use my history, and did someone pay to move this item? Answer both on the line itself.

1. **Name the record:** Show the order count or the similar part that counted, in plain words.
2. **Name the rule:** If a discount or a stock rule changed the order, say so in the same line.
3. **Offer the detail:** Give a link to the full log entry, for the buyer or an auditor who wants it.
4. **Let them push back:** A 'this looks wrong' button sends the case to a person, and the answer feeds the next check.

Explanations carry risk too. A line can reveal private data, such as one person's browsing on a shared account. Limit what each line shows to what that reader should see.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: the short line that says why an item was shown.
- [ ] Where the reason comes from: logged signals, not a guess.
- [ ] The stages: candidates, then ranking, then re-ranking rules.
- [ ] Naming any rule that moved an item.
- [ ] Two designs, and why the logged one is easier to trust.
- [ ] A test that checks each reason against its log.

**Common traps**

- Trap: "The model can tell you its own reason." Better: It can write a reason, but that is a guess unless the text is built from logged signals.
- Trap: "If nothing is logged, make up a plausible reason." Better: Show a plain line or none. An invented reason breaks trust the first time someone checks it.
- Trap: "More detail is always more trustworthy." Better: Match the depth to the reader. A planner needs one line; an auditor needs the log entry.

## Can you spot the wrong reason?

**Spot the wrong reason:** The log for a gate valve shows similar parts, then a supplier discount that moved it up. Which reason line is wrong?

A. Similar to parts your team saved.
B. Recommended because your plant bought this valve last month.
C. Moved up: a supplier discount ends Friday.

**Answer:** B. The log shows no purchase of this valve. The line claims a cause the ranker never used. Build each line from logged codes, and the wrong line can't be written.

**Quick check:** Your recommender explains each pick. Which change makes the explanations more trustworthy?

A. Ask a language model to write a reason from the item title
B. Save the reasons the ranker used, and build the text from them
C. Make the reason texts longer so they sound more convincing
D. Hide the re-ranking rules so the page stays simple

**Answer:** B. A line can only be as true as the record behind it. Logged reasons tie each line to what the system did. Longer text or hidden rules don't change what happened.

## Can you answer these from memory?

**Flash cards**

- **What is a recommendation explanation?** The short line that says why an item was shown, built from what the system used.
- **Why save reasons as the system runs?** So the text can be checked against a real record, not a guess.
- **Post-hoc vs built-in explanation?** Post-hoc is written after the decision. Built-in comes from a model made to be read.
- **Why name re-ranking rules?** A discount or stock rule can move an item. Hiding it makes the reason false.
- **Who is the explanation for?** Tailor it: a planner needs one line, an auditor needs the log entry behind it.
- **How do you test an explanation?** Sample recommendations and check that each reason shown is in that item's log.

## Likely follow-up questions

- Q467 How explainable are LLMs? https://designervenkat.online/interview/ai/how-explainable-are-llms
- Q463 Auditability and audit logs? https://designervenkat.online/interview/ai/auditability-and-audit-logs
- Q247 Offline vs online evaluation? https://designervenkat.online/interview/ai/offline-vs-online-evaluation
- Q258 How do you A/B test an LLM feature? https://designervenkat.online/interview/ai/how-do-you-ab-test-an-llm-feature
- Q126 Rerankers: cross-encoder vs bi-encoder? https://designervenkat.online/interview/ai/cross-encoder-vs-bi-encoder-rerankers

## Learn it in depth

- [Explainable AI: why did it decide that?](https://designervenkat.online/learn/machine-learning/explainable-ai)
- [Recommendation systems: what comes next?](https://designervenkat.online/learn/machine-learning/recommendation-systems)
