Coding prompts
Ready-made prompts for reading, fixing, testing and documenting code, written to get explanations alongside the code.
The coding prompts below cover the jobs where a chat model saves developers the most time: reading unfamiliar code, tracking down a bug, writing tests, refactoring, porting between languages, building SQL queries and regular expressions, designing endpoints and schemas, scripting small chores and getting out of a tangled Git state. There are also prompts for documentation, for learning a concept with a tiny example, and for planning a side project.
Good answers depend on context. Tell the model the language, framework and version, paste the relevant code and the exact error text, and say what you expected to happen. Ask for an explanation alongside the code, and for a list of edge cases before tests, so you can judge the reasoning and not only the output. One prompt uses image understanding: attach a screenshot of a page layout and Llama 4 Maverick or Llama 4 Scout will draft markup and CSS for its structure.
Keep the usual caution. The models have a knowledge cut-off and cannot check current documentation, so a library option may be outdated or invented. Generated code can look right and still fail, so run and test it. Never paste API keys, passwords or customer data; your messages are sent through our server to an inference provider to produce the answer. For very large files, send the function or module that matters, since long messages are trimmed.
See how developers use the Llama chat or open the Code Assistant. To build your own app on Llama, start with the Llama API page.
How to adapt these prompts
- Name the stack and versions, for example "Python 3.12 with FastAPI".
- Paste the smallest code that shows the problem, plus the full error.
- Ask for the plan first on bigger tasks, then the code once the plan looks right.
- Try another model if an answer misses: Llama 3.3 70B sometimes catches what another model overlooked.
-
01
Walk me through this code
Go through this [language] code section by section. For each part, say what it does and why it might be written that way, then point out anything that looks like a bug or a trap for future changes: [paste code]
-
02
Find the bug behind wrong output
This [language] function should [expected behaviour], but with input [example input] it returns [actual output]. Find the cause, explain it in two sentences, and show the corrected function with the changed lines marked: [paste code]
-
03
Write a function from a short spec
Write a [language] function called [name] that [what it does]. Inputs: [inputs and types]. Output: [output]. Handle these edge cases: [edge cases]. Add a short docstring and three example calls with their expected results.
-
04
Refactor for readability
Refactor this [language] code so it is easier to read and change, without altering its behaviour. Use clearer names, split long functions, and remove duplication. Then list each change and why it helps: [paste code]
-
05
Port code to another language
Translate this [source language] code into idiomatic [target language], using its standard library where possible. Keep the same behaviour, and add comments wherever the two languages handle something differently, such as integer division or null values: [paste code]
-
06
Write SQL from a table schema
Here is my schema in [database, e.g. PostgreSQL]: [paste CREATE TABLE statements]. Write a query that [what you need]. Explain the joins and filters you used, and mention any index that would make it faster on a large table.
-
07
Build and explain a regex
I need a [flavour, e.g. JavaScript] regular expression that matches [what to match] but not [what to exclude]. Give the pattern, break it down piece by piece, and list sample strings with match or no match next to each.
-
08
Decode an error message
What does this error mean in plain words? [paste error]. I'm using [language, framework and version] and it appears when I [action]. List the usual causes, what to check first, and a minimal example that reproduces the error.
-
09
Add useful comments and docstrings
Add docstrings and comments to this [language] code in the [style, e.g. Google or JSDoc] format. Explain why things are done where it isn't obvious, skip comments that only repeat the code, and don't change any logic: [paste code]
-
10
Security check of a snippet
Act as a security reviewer for this [language] snippet. Look for injection, unsafe deserialisation, unchecked input, weak hashing and hard-coded secrets. Rate each finding low, medium or high, describe a realistic attack, and show the safer version: [paste code]
-
11
Speed up slow code
This [language] code is too slow when [data size or situation]: [paste code]. Explain where the time goes, estimate its complexity in big-O terms, and suggest faster approaches, starting with the simplest change that would help most.
-
12
Design REST endpoints for a feature
Design REST API endpoints for [feature] in my [type of app]. For each endpoint, give the method, path, request body, response example, status codes and who may call it. Point out decisions I still need to make.
-
13
Write a script to automate a chore
Write a [Bash, PowerShell or Python] script that [task, e.g. renames all photos in a folder by date taken]. It runs on [operating system]. Add a dry-run option that only prints what would happen, and explain how to run it.
-
14
Get out of a Git mess
I'm in this situation with Git: [describe what you did and what git status shows]. I want to [goal] without losing [work to keep]. Give me the commands step by step, explain what each one does, and warn me before any step that can't be undone.
-
15
Recreate a layout from a screenshot
I've attached a screenshot of a page layout I like. Write semantic HTML and modern CSS that reproduce its structure: header, columns, spacing and font sizes, using [plain CSS or a framework]. Use placeholder text and make it responsive for phones.
-
16
Draft a README from the code
Write a README for this project based on the code and notes below. Include a one-line description, installation steps, a usage example, configuration options and how to run the tests. Mark anything you had to guess with TODO: [paste code or notes]
-
17
Explain a concept with a tiny example
Explain [concept, e.g. closures or async/await] in [language] to someone who knows the basics. Use one tiny runnable example, show what it prints, then change one line and explain how the output changes.
-
18
Sketch a database schema
Propose a database schema for [app or feature] that stores [the main things, e.g. users, orders and products]. Show the tables with columns, types, keys and relationships, then explain one trade-off in your design and an alternative.
-
19
Write tests for existing code
Write [framework, e.g. pytest or Jest] tests for this code. Cover the normal case, boundaries, invalid input and one failure from a dependency, using mocks where needed. Name each test after the behaviour it checks: [paste code]
-
20
Plan a small project step by step
I want to build [project idea] with [language or stack] and I have about [hours] hours a week. Break it into milestones I can finish one at a time, list what I need to learn for each, and suggest a simple folder structure to start with.
Ask Llama your first question
No account and nothing to install. Open the chat, type a message and see what Llama can do.
Open Llama chat