Feature Engineering for LLM Applications: How to Build Features That Help Language Models

Feature Engineering for LLM Applications: How to Build Features That Help Language Models

Feature engineering for LLM applications is the work of turning raw data into the inputs a language model can actually use: retrieved passages, structured facts, computed signals and well-shaped context. The central question is whether feature engineering still matters now that large language models can read raw text, and the answer is yes, because a model can only reason well about what it is given, and what it is given is decided by the features, retrieval and context a team builds around it.

In classical machine learning, feature engineering meant building columns in a table. For LLM applications, it means building the whole input: which documents are retrieved, how they are ranked and chunked, which structured facts are attached, and how the resulting context is ordered and trimmed. The model is the same either way; the difference between a good answer and a bad one usually comes from the input, not the model.

Key takeaways

  • Feature engineering for LLM applications means shaping everything the model is given, not just table columns.
  • Retrieval, chunking, ranking and structured signals are the features that matter most.
  • Context is a budget: every token spent on noise is a token taken from useful evidence.
  • Features must be versioned and evaluated like code, because silent changes change answers.
  • Measure the effect of each feature on answer quality, not just on retrieval scores.

What counts as a feature for an LLM

A feature for an LLM application is any prepared input that helps the model answer well. Retrieved passages are features: the model reads them instead of relying only on what it memorised during training. Structured facts are features: a customer tier, an order status or a product price, attached to the prompt, lets the model answer precisely instead of guessing. Computed signals are features too: a similarity score, a freshness flag, a confidence value or a category label all give the model information it would otherwise have to infer.

The test for whether something is a feature is whether changing it changes the answer. If reordering the retrieved passages changes the response, the ordering is a feature. If adding a structured fact stops the model from inventing one, that fact is a feature. Thinking in those terms keeps the work focused: feature engineering is whatever changes the model’s behaviour for the better, measured on real questions. For the retrieval side of the picture, see our guide to advanced RAG techniques, which covers fixing the retrieval failures that most often spoil LLM answers.

Retrieval as feature engineering

Retrieval is the most important feature in most LLM applications, because it decides what evidence the model sees. The first choice is chunking: how documents are split into pieces. Chunks that are too small lose context, so the model sees fragments without the sentence that explains them. Chunks that are too large waste context on irrelevant text and push useful passages out. A good chunk usually covers one idea, keeps its heading or surrounding context, and is small enough that several chunks fit alongside the question.

Ranking is the second choice. A simple keyword search finds exact terms but misses paraphrases, while an embedding search finds meaning but can miss exact names and numbers. Many teams combine the two, then re-rank the combined results with a stronger model or a cross-encoder that scores each passage against the question. The re-ranker is a feature in its own right: it decides the order the model reads the evidence in, and order affects which passages the model trusts. Best for: any retrieval application where the model sometimes answers from the wrong document, or ignores the right one that was retrieved.

Structured data and computed signals

Language models are good at text and unreliable at arithmetic, lookup and exact recall, which is why structured data belongs in the input as a feature rather than left for the model to guess. A product price, a policy date, a user permission or an account balance should arrive as a labelled value, fetched from a system of record, not as a sentence the model has to remember. When the model needs to calculate, the right feature is often the result of the calculation, produced by code, rather than the raw numbers.

Computed signals add information the raw data does not carry directly. A document’s freshness, a source’s reliability, a user’s intent category or a query’s language can all be computed before the prompt is built, and each one helps the model decide what to trust. The rule is to compute in code what code does reliably, and to leave the model the judgement that only language understanding can provide. For how structured data reaches a model, see our guide to how AI retrieves structured data, which covers tables, SQL and knowledge graphs.

Context shaping and the token budget

Context is a budget, and every feature spends from it. A long context window does not remove the need to choose: more context costs more, takes longer, and can make the model less accurate, because relevant evidence gets buried among irrelevant passages. The job of feature engineering is to spend that budget on the evidence most likely to matter, and to leave the rest out.

Ordering matters within the budget. Evidence that appears early or late in the context tends to be weighted more heavily than evidence in the middle, so the most relevant passages should be placed where the model will notice them, and the prompt should say plainly which sources to trust when they disagree. Trimming matters too: removing boilerplate, repeated headers and irrelevant sections from a retrieved passage frees space for another useful passage, and it reduces the chance that the model quotes the boilerplate as fact.

Versioning and keeping features consistent

A feature that changes silently is a bug that is hard to find. If the chunking changes, the embedding model changes, or the ranking changes, the answers change, and nobody can say why unless the change was recorded. Every feature should be versioned: the chunking rules, the embedding model, the retrieval configuration and the prompt template all need identifiers, so that an answer can be traced back to the exact features that produced it.

Consistency between training, evaluation and production matters as much as versioning. A feature that is computed one way during evaluation and another way in production will make the evaluation meaningless. The practical fix is to compute features in one shared place, such as a feature store or a shared retrieval service, rather than copying the logic into each application. For the versioning discipline behind this, see our guide to AI workflow versioning, which covers tracking prompts, models and data together.

Evaluating features, not just models

Features should be evaluated by their effect on answers, not by their effect on intermediate scores. A retrieval change that improves a ranking metric but leaves answer quality unchanged has not helped the user, while a change that slightly worsens retrieval but improves answers, perhaps by adding a structured fact, has. The evaluation set should be real questions with known good answers, scored for accuracy, groundedness and usefulness.

Testing one feature at a time is the only way to know what worked. Change the chunking, measure, then change the ranking, and measure again. Changing several features at once makes the result uninterpretable, and teams that do it end up keeping changes that hurt and discarding changes that helped. A small, stable evaluation set run after every feature change is the cheapest quality control an LLM team can buy.

Comparing feature types for LLM applications

Feature type What it improves Main cost Main risk
Retrieved passages Groundedness, freshness Index and retrieval latency Wrong or stale evidence
Structured facts Precision on numbers and names Integration with source systems Stale values if not refreshed
Computed signals Trust and prioritisation Extra processing per request Signals that mislead the model
Chunking and ordering Context efficiency Tuning and testing time Evidence buried mid-context
Conversation history Continuity across turns Token budget per turn Old context crowding out new
Tool outputs Live data and actions Tool reliability and latency Untrusted tool results

No single feature type carries an application. Retrieved passages provide the evidence, structured facts provide the precision, and computed signals provide the judgement about what to trust. The table helps a team see which type is missing when answers go wrong, rather than blaming the model first.

A developer reviewing ranked search results and document passages on a monitor beside a notebook
Retrieved passages, structured facts and computed signals together form the input a language model actually reasons over.

Feature engineering for LLM applications checklist

  • Each feature is named, versioned and traceable to the answer it produced.
  • Chunks cover one idea, keep their context, and fit several to a prompt.
  • Retrieval combines keyword and embedding search, with re-ranking where it helps.
  • Structured facts are fetched from systems of record, not recalled by the model.
  • Arithmetic and lookup are done in code, with results passed to the model.
  • Context is budgeted, ordered by relevance, and trimmed of boilerplate.
  • Features are computed in one shared place for evaluation and production.
  • Every feature change is tested alone on a stable evaluation set.
  • Evaluation scores answer quality, groundedness and usefulness, not just retrieval.
  • Conversation history is summarised or trimmed before it crowds out new evidence.

Frequently asked questions

Does feature engineering still matter for LLM applications?

Yes. A language model can only reason well about what it is given, and what it is given is decided by retrieval, chunking, ranking, structured facts and context shaping. The model is the same either way; the input is usually what separates a good answer from a bad one.

What is the most important feature in an LLM application?

Usually retrieval: which passages the model sees, in what order, and how they were chunked. If the evidence is wrong, stale or badly ordered, no prompt improvement can fully compensate. Structured facts come next, because they stop the model from inventing numbers and names.

How large should document chunks be?

There is no single right size. A good chunk covers one idea, keeps enough surrounding context to be understood alone, and is small enough that several chunks fit in the prompt alongside the question. Teams should test two or three sizes on real questions rather than guessing.

Should the model do arithmetic itself?

No, where it can be avoided. Language models are unreliable at arithmetic and exact lookup. Compute the result in code and pass it to the model as a labelled fact, so the model can use the number without having to calculate it.

How do I know whether a feature change helped?

Test it alone on a stable set of real questions with known good answers, and score the answers for accuracy, groundedness and usefulness. If only the intermediate retrieval score improved and the answers did not, the change did not help the user.

What is the biggest mistake in LLM feature engineering?

Changing several features at once and then guessing which one mattered. Change one feature, measure, and keep only the changes that improve answers. The second biggest is letting features drift between evaluation and production, so the evaluation stops meaning anything.

Latest articles

Scroll to Top