Langchain 2023-07-08 • By Sanjeev Kumar

Langchain Course Part 1: Prompt Engineering

Langchain Course  Part 1: Prompt Engineering

Today we are going to talk about a very interesting topic which is How to write a prompt in ChatGPT or Bard or any Large Language Model(LLM) so that you can get the best of those.

A prompt is the “Art of asking questions in the right way”. In the real world if we need better bonding with anyone We need to ask better questions and it is considered part of communication skills.

Let us take an analogy to understand it more clearly. Suppose you have an anxiety problem and you go to a doctor for consultancy. the conversation looks something like this.

You: “I have an anxiety problem”;

Doctor: “Can you explain it in more detail like when you get it and what triggers it ?”;

You: “When I go to the stage and have to say something, I get shortness of breath, short of words, shaking hands and a quavering voice“;

Now you have explained it clearly, like “What is the problem, in what context it occurs and what are the symptoms“.

ChatGPT, Bard, and similar platforms expect better questioning from you If rather than visiting a doctor you decided to visit chat.openai.com and asked chatGPT the conversation happens something like this

When the prompt is not clearly written, ChatGPT gives general answers, not specific ones to the problem.

Now see the next image and see when the prompt is made clear the response is more clear and concise and specific to the problem.

For the sake of brevity, I have not pasted the whole response you may copy prompt given below the prompt and see the results yourself.

You are my doctor, I want to consult you regarding this issue , “When I go to stage and try to say something , I got following symptoms 1. Shortness of breath.

2. Short of Words

3. Shaking hands

4. A quavering voice

Can you help be figure out what it is and how to cure this?

Now let us take another example , let us take two variations of prompts

a) Write 10 ways to make money using ChatGPT.

b) Write {count} tips to make money using {source}

count=10

source=ChatGPT

At first look, option a) looks simple but by using b) and just changing count and source we can create as many prompts as possible easily, this is called Templating. It works as a blueprint or mold that can produce prompts by making small input changes. In the programming world, these two inputs (count and source) which can be changed are called input variables.

from langchain import PromptTemplate
            from langchain.chains import LLMChain
            from langchain.chat_models import ChatOpenAI
            import os
            
            user_prompt_template = """ 
                Write {count} tips to make money using {source} 
            """
            prompt_template = PromptTemplate(input_variables=["count", "source"],
                                             template=user_prompt_template)
            
            llm = ChatOpenAI(
                openai_api_key=os.environ["OPEN_API_KEY"], temperature=0.8, model="gpt-3.5-turbo", max_tokens=1024)
            
            llm_chain = LLMChain(llm=llm, prompt=prompt_template)
            print(llm_chain.run(count=2, source="Digital Marketing"))

SK
Written by

Sanjeev Kumar

Founder & Lead Engineer at PrepNew. Building cross-platform Flutter applications, serverless AI backends, and full-stack Dart web architectures.

Continue Reading

Related Posts

Chapter 8: App Store Optimization (ASO) & The Global Localization Engine
Viral App Playbook 2026-10-02

Chapter 8: App Store Optimization (ASO) & The Global Localization Engine

While short-form video and community seeding generate explosive viral spikes, App Store Optimization (ASO) is the engine that provides steady, compound, high-intent organic downloads 365 days a year.

PrepNew Team Read Guide →
Chapter 7: Onboarding Psychology — Designing the 4.8★ First Impression
Viral App Playbook 2026-10-02

Chapter 7: Onboarding Psychology — Designing the 4.8★ First Impression

The first sixty seconds after a user opens your app determine over 80% of its lifetime value (LTV), retention rate, and App Store review rating. Most amateurs treat onboarding as a boring administrative hurdle: forcing account registration, demanding notification permissions immediately on splash screen, and showing static feature carousel slides.

PrepNew Team Read Guide →
Chapter 6: The Minimum Viable Stack — Code vs. No-Code for Maximum Speed
Viral App Playbook 2026-10-02

Chapter 6: The Minimum Viable Stack — Code vs. No-Code for Maximum Speed

One of the most paralyzing traps for aspiring app creators is technical over-engineering. Engineers spend weeks debating Rust vs. Go, React Native vs. Flutter, or Kubernetes vs. Serverless. Meanwhile, non-technical founders wonder whether they can build a six-figure business entirely on visual no-code platforms.

PrepNew Team Read Guide →
← Explore More Technical Guides