Back to blog

Prompt Engineering: How to Talk to AI and Get What You Actually Want

·4 min read·Kodiq Team·Читать на русском
Prompt Engineering: How to Talk to AI and Get What You Actually Want

Prompt Engineering: How to Talk to AI

You've probably noticed: sometimes AI nails it on the first try, sometimes it produces garbage. The difference isn't the model. It's how you asked.

Prompt engineering is the skill of formulating requests to AI so you get predictable, high-quality results. It's not hard, but it requires understanding a few principles.

Why AI "Doesn't Understand"

AI doesn't read minds. It works with exactly what you wrote — literally. When you say "make it pretty," the model doesn't know what "pretty" means to you. When you say "fix the bug," it doesn't know what behavior you consider correct.

The main mistake beginners make: prompts that are too short and too vague.

Five Principles of Good Prompts

1. Context First

Bad:

Write a sort function

Good:

Write a function that sorts an array of objects by a `price`
field (number) in descending order. TypeScript, no external
libraries.

AI doesn't know your project, stack, or constraints. More context = more accurate results.

2. Show an Example

Models learn incredibly well from examples. Instead of a lengthy format description, give a sample.

Transform the data into this format:
{ id: "abc-123", label: "Name", active: true }

Input: [{ name: "Test", status: "on", code: "t1" }]

One example replaces a paragraph of instructions.

3. Break It Into Steps

Don't cram complex tasks into a single prompt. Split them:

  1. "Design a database schema for a blog with comments"
  2. "Write a PostgreSQL migration for this schema"
  3. "Create an API endpoint to fetch a post with its comments"

Each step is a checkpoint. If something goes wrong at step two, you haven't lost everything.

4. Assign a Role

You are a senior frontend developer. Review this React component
for performance issues and suggest fixes.

A role narrows the response space. An AI "specialist" gives deeper, more relevant answers than an AI "generalist."

5. Set Constraints

Without constraints, AI generates what it considers an "average" response. Constraints make results sharper:

  • "Maximum 20 lines of code"
  • "No external dependencies"
  • "Python standard library only"
  • "Explain as if I don't know what an API is"

Advanced Techniques

Chain of Thought

Ask AI to think out loud before answering:

Before writing code, describe your plan step by step.
Then implement it.

This forces the model to structure its reasoning and reduces errors on complex tasks.

Negative Instructions

Sometimes it's easier to say what you don't want:

Build a landing page. Don't use Bootstrap, don't add
animations, don't write code comments.

Iterate Instead of Rewriting

Don't start from scratch every time. Work with what AI already generated:

Good, but:
1. Remove the unnecessary div wrapper
2. Replace px with rem
3. Add a hover effect on the button

Iteration is faster and more precise than regeneration.

Coding Prompts: Cheat Sheet

| Task | Prompt | | ------------- | ------------------------------------------------------------------------------ | | Generate code | "Write [what] in [language]. Requirements: [list]" | | Debug | "Here's the error: [text]. Here's the code: [code]. Find the cause and fix it" | | Refactor | "Simplify this code while preserving behavior. Explain what you changed" | | Review | "Check this code for bugs, vulnerabilities, and bad practices" | | Explain | "Explain this code line by line. I know basic [language] but not [topic]" |

The Golden Rule

If AI gave a bad answer, it's not AI's fault. It's feedback: your prompt can be improved. Rephrase, add context, give an example. Treat AI like a very smart but very literal colleague.

Prompt engineering isn't talent. It's a skill that improves with practice. The more you work with AI, the better you formulate — and the faster you get results.