AI Dislikes Ambiguity: A Probability Guide

AI Dislikes Ambiguity: A Probability Guide

4 Min Read

We often perceive Large Language Models (LLMs) as intelligent chat boxes, akin to knowledgeable colleagues. This isn’t far from reality today, having surpassed the “stochastic parrot” stage. As with human interaction, more specific queries yield more useful responses.

Each prompt you send defines a probability distribution. You provide context (input tokens), and the model calculates the most likely or useful output tokens based on its neural network’s weights.

Effectively constraining that distribution leads to precise, production-ready code. Conversely, vague prompts, assumptions of understanding context, or ignoring edge cases force the AI to guess, expanding the continuation space and resulting in many mediocre outcomes.

In engineering, bogus results are termed “hallucinations,” but they’re actually probability drift caused by unclear guidance. This happens when we fail to anchor the model’s path to a high-quality distribution.

To address this, we should stop merely “chatting” and start “architecting.” Let’s explore what happens when we ignore the mechanism.

### The “Hostile” Prompt

I refer to the following prompt as “hostile” because it disregards the model’s statistical nature, assuming it can read minds rather than match patterns.

**The Prompt:**

> Write a function to fetch user data from an API and save it to state.

This simple request contains three specific specification gaps that can break your production app:

1. **The Tutorial Bias:** The model’s training data is biased toward simple tutorials where APIs never fail. Without constraints, it defaults to this “Happy Path,” the statistically most common pattern.

2. **Type Blindness:** It generates generic JavaScript instead of strict TypeScript due to unnegotiated constraints.

3. **The State Gap:** It writes fetch logic instantly, without handling intermediate states (e.g., loading/error), resulting in UI flashes.

#### 🛠 The “Before” Output (The Drift)

“`javascript
useEffect(() => {
fetch(‘/api/users’)
.then(res => res.json())
.then(data => setUsers(data));
// Missing error handling, race conditions.
}, []);
“`

This code aims for brevity over production readiness. It lacks cancellation, error boundaries, and loading indicators.

### The Theory (Why This Happens)

Why did the AI provide mediocre code? It’s a failure of Contextual Anchoring. The model works on a complex Transformer architecture which can be summarized:

1. **Ingest:** Maps input tokens into a high-dimensional vector space.
2. **Attention:** Calculates attention weights, deciding which previous tokens matter most in predicting the next one.
3. **Sampling:** Selects the next token based on calculated probabilities.

#### The Limitation: Attention Decay

The model’s attention mechanism has a limit, suffering from Token Locality. As conversations extend, earlier tokens’ influence, such as initial instructions, can diminish. Effective engineers re-inject crucial constraints (e.g., “Use strict TypeScript”) nearer to the generation point.

#### The “Likelihood” Mistake

Our hostile prompt ignored this mechanism. We provided a short, vague input, leaving the “search space” for an answer too broad. Saying “Write a function,” the model picks the path of least resistance: the tutorial snippet. Undefined constraints lead the model to fill the gap with its dataset’s common pattern.

Transitioning from **Implied Intent** (hoping for understanding) to **Explicit Constraint** (steering distribution towards quality) is necessary.

### Solutions

We will make three specific negotiations with AI to ensure stability:

1. **The Persona Negotiation (System Context):** The AI’s provision of simple scripts aligns with its “helpful assistant” pattern. We must narrow this to “Senior Engineering.” Implement a system prompt, or global context, such as a `claude.md` or `agents.md` file containing: _”You are a Senior Frontend Engineer prioritizing defensive coding. You reject ‘happy path’ code and always implement error handling, type safety, and cleanup functions.”_

2. **The Format Negotiation (Output Constraints):** Similar to how browsers struggle when elements load unordered, AI struggles with mixed conversation and code. Use strict structure: include prompts like _”Return only the code block. Do not add introductory text. Ensure strict typing with TypeScript.”_

3. **The Logic Anchor (Chain of Thought):** This technique is vital. Usually, the AI predicts code token-by-token instantly, similar to coding without a plan. Asking for a “plan” first biases the attention weights for the ensuing code. Prompt a plan first, for example: _”List the 3 most likely failure modes (e.g., race conditions, network errors) and explain preventive measures.”_

### Phase 4: The “Stable” Interaction

Here is a refined prompt for the same task, properly negotiated.

**The Orchestrated Prompt:**

> Write a useUsers hook.
> 1.

You might also like