Prompt / intent before data
The first LLM call rewrites the user's query into search-ready terms. We learn what prompt engineering buys — and discover the output shape problem that makes Schema necessary.
Architectural Position
- fn
- The LLM call, shaped by your system prompt
- query_user
- Raw natural language input from the user
- prompt_rewrite
- The system prompt for rewriting — instructs fn to convert natural language into search-ready terms
- query_refined
- Rewritten query — optimised for semantic search over phone narratives
- results
- Ranked phone results from semantic similarity search
Step by Step
# The failure at Layer 1
query_user: "something for my mom who struggles
with technology"
BM25 tokens: [something, mom, struggles, technology]
Matches: 0
# Layer 2 fix: route through LLM first
# fn(query_user, prompt) rewrites before searchingBM25 has no model of intent. The Prompt layer adds one — the rewrite step uses an LLM call to map the query into search-ready terms.
Implementation
What you build
- A system prompt instructing the model to rewrite queries for semantic search
rewrite: a single LLM call that takesquery_userand returnsquery_refinedretrieve: semantic search over narrative embeddings usingquery_refined
What it fixes
Intent now maps to semantic search space. "Something for my mom who struggles with technology" becomes "simple large display easy navigation elderly."
Key Concepts
- System prompt
- The fixed instructions sent to the model before every user message. Sets the role, task, and constraints for all responses.
- Zero-shot prompting
- Asking the model to perform a task with instructions alone, no examples. Works for common tasks; degrades on precise requirements.
- Chain-of-thought prompting
- Instructing the model to reason step-by-step before answering. Forces intermediate thinking — most reliable for consistent, structured output.
- Few-shot prompting
- Including examples of correct input–output pairs in the prompt. Helps the model understand the format and style you need.
The Failure
The Ambiguity LawLanguage always under-specifies intent. The model fills the gap.
The same query runs twice through rewrite. Run 1 returns "simple smartphone easy navigation elderly large screen". Run 2 returns {"category": "budget", "user": "elderly", "features": ["large display"]}. Same input, different shape. The downstream code that expected a plain string now receives an object. Layer 3 exists because of this failure.
What it reveals
query_refined is inconsistent — sometimes a sentence, sometimes fragments, sometimes a JSON object. Downstream code cannot rely on the shape.