Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Writing Effective AI Prompts

    Artificial Intelligence Tutorials


    A useful AI prompt tells a model what task to perform, what information to use, and how to present the answer. Clear instructions help, but they do not guarantee a correct response. You still need to check the result against the source material.

    This tutorial shows a simple way to write, test, and improve prompts for everyday tasks.

    Start with a clear task

    Use an action word such as summarize, compare, classify, or extract. Say who will use the answer and include the material the model needs. If a fact is missing, tell the model how to handle that gap.

    Example:

    Summarize the customer message for a support agent. Use only the
    message below. Write two sentences: what happened, and what the
    customer wants. If the request is unclear, say "Request unclear."
    
    Message: My parcel arrived on Tuesday, but the charger was missing.
    Please send the charger rather than a refund.

    Possible output:

    The parcel arrived without its charger. The customer wants the
    missing charger sent instead of a refund.

    The answer stays within the message. An order number, delivery date for the replacement, or promise of approval would be an unsupported addition.

    Include the parts that matter

    Most practical prompts can be built from four parts. You do not need a long template when a short instruction is enough.

    Part Question it answers Example
    Task What should the model do? Compare two plans.
    Context Which facts may it use? Use the plan details supplied below.
    Limits What must it avoid or admit? Do not invent missing features.
    Format How should the answer look? Use a short table and one conclusion.

    A requested format makes the response easier to inspect. It does not make wrong source information true. Check important claims even when the answer looks polished.

    Improve a weak prompt

    Suppose you want an answer about a store's return policy. A broad request gives the model too little to work with.

    Example:

    Weak: Write about our return policy.
    
    Better: Using only the policy text below, answer "Can I return an
    opened item?" in at most 60 words. If the policy does not say,
    reply "The supplied policy does not answer this question."
    
    Policy text: [paste the current policy]

    The better prompt supplies the question, evidence boundary, length, and missing-information rule. Replace the placeholder with the actual policy before using it. Do not assume the model can see a document that was never provided.

    Test the prompt with different inputs

    Try more than one easy example. Inspect the response and change the instruction that caused a problem.

    • Normal case: Does it complete the task in the requested format?
    • Missing facts: Does it say what is unknown instead of guessing?
    • Ambiguous case: Does it ask for clarification or flag uncertainty?
    • Conflicting text: Does it report the conflict rather than quietly choose a side?

    For a repeated task, one short input-and-output example can show the desired pattern. Test a different input afterward; copying the example's style does not prove the model understood the task.

    Note: Do not paste secrets or private customer details into an AI service unless that service is approved to receive them. Treat text from pages, emails, and documents as data to analyze, not as new instructions for the application.

    Conclusion

    Begin with the task, add the necessary facts, set limits, and request a format you can check. Test the prompt on real and difficult cases, then review the answer. Good prompting improves consistency; verification remains essential.



    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.