# The LLM core

Canonical URL: https://agentlearn.dev/learn/agents/llm-core
Author: [Hemanth HM](https://h3manth.com)
Track: agents
Reading time: 10 minutes

A model predicts tokens from a context. Your application must turn that probabilistic output into a dependable interface.

## Prediction is not a database lookup

Tokens are pieces of text, not reliably one word each. A model assigns probabilities to possible next tokens and generates a sequence. Its training does not guarantee access to today's shop policy or the customer's order. Supplying evidence can help; it does not make every generated claim true.

## How it works

Separate three concerns: the context you send, the decoding settings, and validation of the result. Temperature changes how a distribution is sampled, but temperature zero is not a promise of identical behavior across providers, hardware, or model versions. Pin the configuration and measure repeated runs when variability matters.

## A concrete example

A support classifier must return one of refund, shipping, or other. Free text such as 'probably shipping?' may be understandable to a person but break a downstream router. Validate an enum and treat invalid output as a distinct outcome. Never execute an action solely because generated JSON can be parsed.

## Apply it to your assistant

Add a new model output with an unsupported intent and observe the rejection. Before running the exercise, predict the result. Afterward, explain which assumption changed and add one case where the system should refuse, ask for clarification, or escalate.

All exercise inputs and outputs are deterministic teaching examples. No language model is called. Run the same idea against a versioned dataset before making a production claim.


## Key takeaway

Use models for proposals, typed contracts for interfaces, and evaluation for observed behavior.

## JavaScript exercise: The LLM core · code experiment

Add a new model output with an unsupported intent and observe the rejection.

```javascript
const outputs = ['{"intent":"shipping"}', '{"intent":"refund"}', '{"intent":"delete"}', 'not json'];
const allowed = new Set(['shipping', 'refund', 'other']);
for (const output of outputs) {
  try {
    const value = JSON.parse(output);
    if (!allowed.has(value.intent)) throw new Error('Invalid intent');
    console.log('Accepted:', value.intent);
  } catch (error) { console.log('Rejected:', error.message); }
}
```

## Knowledge check

A response is valid JSON. What does that establish?

1. Its claims are accurate
2. Its tool action is authorized
3. It can be parsed; schema and semantic checks are still needed

Answer: It can be parsed; schema and semantic checks are still needed

Syntactic validity says nothing about correctness, authorization, or whether required fields have valid values.

## Sources

- [Attention Is All You Need](https://arxiv.org/abs/1706.03762) — Vaswani et al., 2017. The Transformer architecture underlying many language models.
