← Learning Hub
Advanced

Large Language Models and Prompting

A large language model (LLM) is a huge neural network trained on lots of text to predict the next word. That simple goal, at a giant scale, gives it skills like writing, summarising, translating, coding and answering questions.

Large language models are general-purpose tools you can use without training anything: you describe the task in plain language. The quality of the answer depends a lot on the quality of the prompt, and on checking the output - LLMs can sound confident while being wrong.

Tokens

LLMs read text as tokens - pieces of words. Prices and limits for AI services are counted in tokens. Roughly, 1 token is about 4 characters of English text; Hindi and other languages often use more tokens per word.

Writing good prompts

  • Be specific: say the audience, length and format you want
  • Give context: paste the data or text it should use
  • Show an example of a good answer
  • Break big jobs into steps, and ask it to check its work
  • Ask for a structure such as a table or JSON when a program will read the reply
Example
Weak prompt:
  Write about our product.

Better prompt:
  Write a 60-word product description for a steel water bottle (1 litre, keeps water
  cold for 24 hours, Rs 499) for Indian college students. Friendly tone, simple English,
  end with one line about free delivery above Rs 499. Don't use exclamation marks.

Calling an LLM from code

AI companies offer an API. You send a prompt and get text back. Keep the API key secret in an environment variable, never in your code. Check the provider's current documentation for the exact model names and prices - they change often.

Example
# pip install anthropic   (example with the Anthropic Python library)
import os
import anthropic

client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
reply = client.messages.create(
    model="MODEL-NAME-FROM-THE-DOCS",
    max_tokens=300,
    messages=[{"role": "user", "content": "Explain GST to a 12-year-old in 3 sentences."}],
)
print(reply.content[0].text)

Know the limits

  • LLMs can state wrong facts confidently ("hallucinate") - check anything important
  • Their knowledge stops at a training date unless they can search
  • Don't paste passwords, customer data or private documents into tools you don't control
  • RAG (retrieval augmented generation): give the model your own documents to answer from, so answers are grounded in your data
Key points
  • LLMs predict the next token at huge scale.
  • Specific prompts with context and examples work best.
  • Check important facts; protect private data.

📝 Test yourself

1. What does an LLM learn to do during training?
2. Which is a better prompt?
3. Complete:
LLMs read text as pieces called .