AI & LLM Interview Questions
Core questions on how large language models work, how to prompt and adapt them, and how to run them safely.
A large language model is a neural network, typically a transformer, trained on large amounts of text to predict the next token given the previous ones. Generation repeats that prediction step, sampling one token at a time. Settings such as temperature control how random the choice is.
The context window is the maximum number of tokens a model can consider at once, including the prompt and its own output. It limits how much documentation, history or retrieved text you can supply. Longer contexts cost more and can reduce accuracy when relevant facts are buried in the middle.
Attention lets each token weigh how relevant every other token is when building its representation. The model computes scores between tokens, turns them into weights and mixes information accordingly. This is how the model links a pronoun to its noun even when they are far apart.
Clear instructions, a defined output format such as JSON with a schema, a few representative examples and explicit handling of edge cases. Version prompts like code and test them against a fixed evaluation set before changes go live.
Zero-shot gives only instructions. Few-shot adds examples of the desired input and output. Chain-of-thought asks the model to reason step by step before answering, which can improve multi-step problems but increases cost and latency.
Fine-tune to change style, format or behaviour consistently, or to get a smaller cheaper model to do a narrow task well. Use retrieval when the issue is missing or changing knowledge. Try prompting and retrieval first because they are faster to iterate and easier to update.
LoRA, or low-rank adaptation, freezes the original model weights and trains small added matrices instead. It needs far less memory and compute than full fine-tuning, produces small adapter files and lets you swap adapters for different tasks on the same base model.
Hallucination is when a model produces confident but unsupported or false output. Reduce it by grounding answers in retrieved sources, requiring citations, allowing the model to say it does not know, lowering temperature for factual tasks and verifying outputs automatically where possible.
Prompt injection is when untrusted text, such as a web page or email, contains instructions that hijack the model's behaviour. Defences include separating trusted instructions from untrusted data, limiting tool permissions, validating outputs, requiring human approval for sensitive actions and never treating model output as trusted code.
Use a smaller model where quality allows, shorten prompts, cache repeated requests, stream output to improve perceived speed and batch requests where possible. For self-hosted models, quantisation and efficient serving frameworks improve throughput.
Build a labelled test set from real use cases, define pass criteria per case and run it on every change. Combine automated checks, model-based graders validated against human judgement, and periodic human review of sampled production outputs.
A base model is trained only to predict text and may continue a prompt rather than follow it. An instruction-tuned model is further trained on instruction and response examples, often with preference feedback, so it follows requests and holds a conversation.