> ## Documentation Index
> Fetch the complete documentation index at: https://genai.codewithsiva.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Prompt Engineering

> Learn the art and science of communicating effectively with Large Language Models

Welcome to the **Prompt Engineering** module. This module explores how to design, optimize, and programmatically manage prompts to get consistent, high-quality, and structured outputs from LLMs.

## 💻 Module Practice Notebooks

Master all the concepts from this module with hands-on practice:

* **Practice in VS Code**: Open the notebook in your local editor. Requires a local `.env` file containing your API keys.
* **Practice in Google Colab**: Open the notebook directly in Colab. Setup cells are included to install packages and request API keys.

[💻 VS Code](vscode://file/Users/sivaprasad/Downloads/GenAI%20With%20Python/public/notebooks/prompt-engg/prompt-engineering-practice-vscode.ipynb) | [🚀 Colab](https://colab.research.google.com/github/prasad230776/genai-course/blob/master/public/notebooks/prompt-engg/prompt-engineering-practice-colab.ipynb) | <a href="/public/notebooks/prompt-engg/prompt-engineering-practice-vscode.ipynb" download>📥 Download Notebook</a>

## 🗺️ Module Overview

Learn how to control LLM outputs deterministically:

```mermaid theme={null}
graph TD
    A["Core Prompting Principles<br/>(Clarity, Context, Constraints)"]
    --> B["Advanced Architectures<br/>(Few-Shot, CoT, ReAct)"]
    --> C["Structured Output Parsing<br/>(JSON Mode & Pydantic Validation)"]
    --> D["Practical Capstone<br/>(Natural Language to SQL Generator)"]
```

## 📚 Module Curriculum & Roadmap

Explore the sections in this module using the cards below:

<CardGroup cols={2}>
  <Card title="1. Introduction to LangChain" icon="handshake" href="/prompt-engg/01-introduction">
    Why LangChain is needed, the difference between traditional and GenAI applications, setting up projects with `uv`, managing `.env` keys, and initializing Groq/Gemini chat model providers.
  </Card>

  <Card title="2. Prompt Templates & Messages" icon="memo-circle-check" href="/prompt-engg/02-prompt-templates">
    Defining string-based `PromptTemplate` and message-based `ChatPromptTemplate` schemas, understanding message objects (`SystemMessage`, `HumanMessage`, `AIMessage`), variable passing, and response extraction techniques.
  </Card>

  <Card title="3. LCEL & Runnables" icon="brackets-curly" href="/prompt-engg/03-lcel-chains">
    Building pipelines using LangChain Expression Language (LCEL) and the pipe (`|`) operator, managing `invoke()` vs. `stream()` flows, and using runnables like `RunnablePassthrough`, `RunnableSequence`, and `RunnableParallel`.
  </Card>

  <Card title="4. Output Parsers" icon="brackets-square" href="/prompt-engg/04-output-parsers">
    Converting raw text generated by LLMs into structured Python structures: strings (`StrOutputParser`), lists (`CommaSeparatedListOutputParser`), dictionaries (`JsonOutputParser`), or validated data objects (`PydanticOutputParser`).
  </Card>

  <Card title="5. Model Hyperparameters" icon="sliders" href="/prompt-engg/05-model-parameters">
    Controlling token selection, randomness, and length using parameters like Temperature, Max Tokens, Top-K, and Top-P.
  </Card>

  <Card title="6. Few-Shot & Sequential" icon="shuffle" href="/prompt-engg/06-fewshot-sequential">
    Advanced prompting patterns, explaining why few-shot example formatting is required, setting up `FewShotPromptTemplate`, and composing sequential chains where outputs feed directly into subsequent prompts.
  </Card>
</CardGroup>

## 🛠️ Practical Capstone Project

### Natural Language to SQL Generator

Build a python tool that:

1. Takes a user's natural language request (e.g., "Find the top 3 employees with the highest salary").
2. Merges it into a prompt template containing your SQLite database schema definition.
3. Requests the LLM to generate a structured JSON object containing the raw SQL query and a short explanation.
4. Validates the JSON schema with Pydantic, executes the generated SQL query against a test database, and prints the resulting records.
