← Back to list

Prompt Engineering with Llama 2 & 3: My Learning Journey

I recently completed a course on Prompt Engineering with Llama 2 and Llama 3, and it helped me understand the Llama ecosystem from both a…

Sarath V · 2026-05-19 11:29 · 0 claps · 7.8 min read
#llama-2 #llama-3 #large-language-models
Open on Medium ↗
Wiki topics: LLM · Large Language Models PE · Prompt Engineering EDU · Education & Learning

Prompt Engineering with Llama 2 & 3: My Learning Journey

I recently completed a course on Prompt Engineering with Llama 2 and Llama 3, and it helped me understand the Llama ecosystem from both a practical and responsible AI perspective.

Before this course, I had already explored several areas of Generative AI, including:

  • Prompt engineering basics
  • RAG
  • LangChain
  • LangGraph
  • Agentic AI
  • Fine-tuning
  • LLMOps
  • Evaluation and debugging

But this course gave me a more focused view of how to work with open LLMs, especially the Llama family of models.

The biggest takeaway for me was this:

Prompt engineering is not just about asking better questions. It is about understanding the model, its format, its limitations, and its safety boundaries.

This article is a reflection of what I learned from the course.

Why Llama Models Matter

The Llama family of models has become an important part of the open-source LLM ecosystem.

While many developers start their GenAI journey using hosted APIs, Llama introduces a different perspective:

  • More flexibility
  • More control
  • Local or private deployment possibilities
  • Strong ecosystem support
  • Specialized variants for chat and code

The course started by introducing the Llama ecosystem, model training concepts, access options, and the different types of models available.

This helped me understand that using Llama effectively is not only about writing prompts. It also requires knowing:

  • Which model variant to choose
  • How to structure prompts
  • How to manage context
  • How to handle safety
  • How to work with code-focused models

Exploring Llama Models and the Ecosystem

One of the first topics covered was the broader Llama ecosystem.

The course introduced:

  • Llama models
  • Model training concepts
  • Access options
  • Code Llama variants
  • Safety and security considerations

This was important because not every Llama model is meant for the same use case.

For example:

  • Base models are more general-purpose.
  • Chat models are optimized for conversations.
  • Code Llama models are designed for programming-related tasks.
  • Llama Guard helps with safety classification.

The key lesson was:

Choosing the right model is part of prompt engineering.

A well-written prompt given to the wrong model may still produce poor results.

Getting Started with Llama Prompting

The course then moved into prompting with Llama 2.

One of the most practical parts was understanding how prompts need to be formatted.

With chat models, prompt structure matters.

For Llama-style instruction prompting, we often need to think about:

  • Instruction tags
  • System instructions
  • User messages
  • Assistant responses
  • Output length
  • Token limits

A simplified prompt structure may look like:

[INST]
Explain the concept of REST APIs in simple terms.
[/INST]

For multi-turn conversations, the structure becomes even more important because the model needs prior context to respond correctly.

The key takeaway:

Prompt format is not decoration. It directly affects model behavior.

Controlling Output Length and Tokens

Another useful topic was controlling output length.

In real applications, this matters a lot.

If the output is too long:

  • Cost increases
  • Latency increases
  • User experience suffers
  • Responses may become unfocused

If the output is too short:

  • Important details may be missed
  • The answer may feel incomplete

The course covered how to guide output length through prompt instructions and token settings.

For example:

Explain this concept in 5 bullet points.
Keep each bullet under 20 words.

This kind of explicit instruction helps produce more usable outputs.

My key learning:

Good prompts define not only what the model should answer, but also how the answer should be shaped.

Understanding Multi-Turn Conversations

Single-turn prompts are useful, but real applications often require conversations.

The course covered:

  • Multi-turn interactions
  • Context building
  • Model limitations
  • Chat prompt implementation in code

This helped me understand that LLMs do not “remember” like humans unless we explicitly provide context.

In a chat application, we need to decide:

  • How much history to send
  • Which messages are important
  • When to summarize older context
  • How to avoid exceeding context limits

A multi-turn conversation may include:

User: What is FastAPI?
Assistant: FastAPI is a Python web framework...
User: How is it different from Flask?
Assistant: Compared to Flask...

But behind the scenes, the application must manage that conversation context carefully.

The key takeaway:

Chat memory is an application design problem, not just a model feature.

Prompt Engineering Basics

The course then covered core prompt engineering techniques.

These included:

  • Zero-shot prompting
  • Few-shot prompting
  • Role-based prompting
  • Summarization with context
  • Chain-of-thought style reasoning
  • Prompt engineering best practices

Zero-Shot Prompting

Zero-shot prompting means asking the model to perform a task without examples.

Example:

Classify the following feedback as Positive, Negative, or Neutral:
"The app is fast, but the UI is confusing."

This is simple and often works well for common tasks.

But for more specific output formats, it may not be enough.

Few-Shot Prompting

Few-shot prompting provides examples.

Example:

Classify the sentiment.
Input: "The product is excellent."
Output: Positive
Input: "The delivery was late."
Output: Negative
Input: "The UI is clean but slow."
Output:

Few-shot prompting helps the model understand the pattern.

The key learning:

Examples often work better than long explanations.

Role-Based Prompting

Role prompting gives the model a specific identity or responsibility.

Example:

You are a senior backend architect.
Review the following API design and suggest improvements.

This helps steer tone, depth, and perspective.

Role prompting is especially useful when the same input can be answered from different angles:

  • Beginner explanation
  • Architect review
  • Security review
  • Code optimization
  • Business summary

Summarization with Context

The course also covered summarization.

Summarization sounds simple, but context changes everything.

For example:

Summarize this document for a junior developer.

is different from:

Summarize this document for a CTO evaluating technical risk.

The same document can produce different summaries depending on audience and purpose.

The learning here was:

A good summary is not just shorter text. It is context-aware compression.

Chain-of-Thought Reasoning

The course introduced reasoning-oriented prompting patterns.

The goal is to help the model break down complex tasks before producing an answer.

For example:

Solve this step by step.
First identify the known facts.
Then apply the formula.
Finally give the answer.

This is useful for:

  • Math problems
  • Logical reasoning
  • Planning
  • Debugging
  • Decision analysis

However, reasoning prompts should be used thoughtfully. In many production systems, we may want structured reasoning internally but a clean final response externally.

My takeaway:

Complex tasks often need decomposition, not just direct generation.

Llama Model Variants: 7B, 13B, 70B and Chat Models

Another important section was understanding Llama model variants.

The course covered different model sizes such as:

  • 7B
  • 13B
  • 70B
  • Chat models

The general trade-off is:

Smaller ModelsLarger ModelsFasterBetter reasoningLower costHigher resource needsEasier to deployBetter qualityUseful for focused tasksBetter for complex tasks

This helped clarify that model selection depends on the use case.

For example:

  • A simple classification task may not need a large model.
  • Complex reasoning may benefit from a larger model.
  • A chat application should usually use a chat-optimized variant.
  • Local deployment may require smaller models due to hardware constraints.

The key learning:

Bigger is not always better. The best model is the one that fits the use case, latency, cost, and quality requirements.

Code Llama

The course also introduced Code Llama and its variants.

This was especially interesting from a developer perspective.

Code Llama can help with:

  • Code generation
  • Code completion
  • Explaining code
  • Refactoring
  • Debugging
  • Generating tests

Example prompt:

Write a Python function to read a JSON file and validate required fields.

Another example:

Explain what this Java method does and suggest improvements.

The course also covered Code Llama’s extended context window, which is useful when working with larger codebases or longer files.

The key takeaway:

Code-focused LLMs are not just general chat models with coding ability. They are optimized for programming workflows.

Code Security and Safety

One of the practical reminders in the course was that code generation should be handled carefully.

Generated code may:

  • Contain security vulnerabilities
  • Use outdated libraries
  • Miss edge cases
  • Ignore input validation
  • Produce inefficient logic

So developers should not blindly copy generated code.

For production use, generated code should go through:

  • Code review
  • Static analysis
  • Security scanning
  • Unit testing
  • Integration testing

The key learning:

AI-generated code still needs engineering discipline.

Llama Guard and Safety

One of the most important parts of the course was Llama Guard.

Llama Guard is used to help detect unsafe content in both input and output.

The course covered:

  • Safety challenges
  • How Llama Guard evaluates content
  • Building prompts to detect unsafe content
  • Testing examples
  • Attempting to trick safety systems

This was a valuable reminder that safety should be part of the application architecture.

A typical safety flow may look like:

User Input
   ↓
Safety Check
   ↓
LLM Response
   ↓
Output Safety Check
   ↓
Final Response

The important point is that safety is not only about filtering user input.

We also need to evaluate model output.

The key takeaway:

Responsible AI requires checking both what goes into the model and what comes out of it.

Prompt Engineering Best Practices I Took Away

Based on the course, these are the practices that stood out to me.

1. Be Explicit

Instead of:

Explain APIs.

Use:

Explain REST APIs to a beginner backend developer.
Use a simple example.
Keep the answer under 200 words.

2. Define the Role

You are a senior Python engineer.
Review the following code for readability and performance.

3. Provide Examples

Examples help the model understand the expected format.

4. Control the Output

Specify:

  • Length
  • Format
  • Tone
  • Audience
  • Structure

5. Build Context Carefully

For multi-turn conversations, include only relevant context.

Too little context leads to poor answers.

Too much context can confuse the model or increase cost.

6. Choose the Right Model

Use smaller models for simpler tasks and larger models for complex reasoning.

Use Code Llama for coding workflows.

Use Llama Guard for safety checks.

7. Validate Outputs

Never assume the model is always correct.

For production systems, responses should be validated, tested, and monitored.

Prompt Engineering with Llama vs General Prompting

Prompt engineering with Llama has some unique considerations.

The biggest difference is that working with Llama often gives more control, but also more responsibility.

What Changed in My Thinking

Before this course, I saw prompt engineering mostly as:

Writing better instructions.

After this course, I see it as:

Designing the full interaction between user, model, context, code, and safety layers.

That includes:

  • Model selection
  • Prompt formatting
  • Context construction
  • Output control
  • Conversation design
  • Code generation safety
  • Input/output moderation

This is a much more complete view.

Key Takeaways

1. Prompt Format Matters

Especially with instruction-tuned and chat models.

2. Context is a Design Choice

Good responses depend on good context management.

3. Examples Improve Reliability

Few-shot prompting is often more effective than long instructions.

4. Model Choice Matters

7B, 13B, 70B, chat, and code models serve different needs.

5. Code Generation Needs Review

Code Llama is powerful, but developer judgment is still required.

6. Safety Must Be Built In

Llama Guard highlights the importance of checking both prompts and responses.

Final Thoughts

This course helped me understand that prompt engineering with Llama is not just about asking questions.

It is about building reliable, safe, and context-aware interactions with open LLMs.

As Llama models continue to evolve, they open up exciting possibilities for:

  • Private AI assistants
  • Code generation tools
  • Domain-specific chatbots
  • Local AI applications
  • Safer GenAI workflows

The biggest lesson for me was:

Better prompts come from better system understanding.

When we understand the model, its format, its limitations, and its safety mechanisms, we can design much better LLM-powered applications.

Closing Note

If you are exploring:

  • Open-source LLMs
  • Prompt engineering
  • Code generation
  • Llama models
  • AI safety
  • LLM-powered applications

then learning prompt engineering with Llama 2 and 3 is definitely worth it.


메타데이터
post_id
08ddd21fee58
slug
prompt-engineering-with-llama-2-3-my-learning-journey-08ddd21fee58
url
https://medium.com/@sarathvk619/prompt-engineering-with-llama-2-3-my-learning-journey-08ddd21fee58
canonical_url
https://medium.com/@sarathvk619/prompt-engineering-with-llama-2-3-my-learning-journey-08ddd21fee58
author_url
https://medium.com/@sarathvk619
status
ok
fetched_at
2026-06-09 15:37:30