KI 2.4 — Coding mit KI

Code-Prompts strukturiert schreiben

Ein guter Code-Prompt enthält vier Zutaten: Kontext, Aufgabe, Constraints, Format. Ohne diese vier ratet die KI — und die rät oft generisch.

Schlechter Prompt

schreib mir eine Login-Funktion

Die KI weiß nicht: welche Sprache? Framework? Auth-Mechanismus? Datenbank? Output-Format?

Guter Prompt

Kontext: Next.js 15 App Router, PostgreSQL via pg, JWT in HttpOnly-Cookie.
Aufgabe: Schreib login(email, password) → returns { ok, token, error? }.
Constraints:
  - bcrypt.compare gegen users.password_hash
  - Bei Fehler: { ok:false, error:"invalid" } (kein Detail-Leak)
  - JWT mit { uid, role }, 7 Tage gültig, secret aus process.env.JWT_SECRET
Format: TypeScript, eine async function, kein try/catch außenrum.

Die 4 Zutaten im Detail

  • Kontext — Tech-Stack, Codebase-Konvention, was schon existiert
  • Aufgabe — was soll die Funktion / Komponente / Endpoint machen
  • Constraints — Errors, Sicherheit, Performance, was NICHT erlaubt ist
  • Format — Sprache, Datei-Ort, Style (functional / class / arrow)

Faustregel: wenn ein Junior-Dev mit deinem Prompt loslegen könnte, kann es die KI auch.

Zurück zu KI