Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 6 min read

Cap the agent at 10 turns and scope tools in code

Build the first agent as a short loop: one model, a trigger, a prompt plus input, a few atomic tools, and a budget of up to 10 turns. Take the tenant ID from the authenticated session and hard-code it inside the tool, so

Cap the agent at 10 turns and scope tools in code

Build the first agent as a short loop: one model, a trigger, a prompt plus input, a few atomic tools, and a budget of up to 10 turns. Take the tenant ID from the authenticated session and hard-code it inside the tool, so the model has no argument it can swap for another tenant. Tool responses join the next prompt, so you cannot escape them the way you escape a SQL string.

Malte Ubl, CTO at Vercel, described this pattern on Chain of Thought in September 2025.

How do you structure the first version of an agent?

Use one model, a trigger, input and a prompt, and a small set of simple tools, then allow up to 10 turns toward the goal. For a coding agent, Malte named read files, list files, edit files, and create pull requests. For research, he named a search tool and a generic SQL tool against Snowflake. He wants those tools atomic.

Each model call starts from scratch. Pass the prior messages back in, including the last tool result, and the model does token completion on that text. State the goal, what each tool is for, and the turn cap. If the model says it is done before the cap, stop.

... you get to make up to 10 turns using a tool that's towards your goal, and then you just let it cook.

Malte Ubl, CTO at Vercel, on Chain of Thought ep 39

Vercel's Playbook for AI Agent… - Chain of Thought | AI Agents, Infrastructure & Engineering - Apple Podcasts

Podcast Episode Β· Chain of Thought | AI Agents, Infrastructure & Engineering Β· September 10, 2025 Β· 54m

favicon podcasts.apple.com

Before the loop, run his vibe check. Paste the task and the rules into a chat model. False positives, or missed problems, mean it is not ready. If the answer looks usable, connect the agent to the systems that hold the data. He called that plain workflow integration, work a backend engineer already does.

How do you stop a model from changing the tenant on a query?

Hard-code the tenant condition in the tool and fill it from the session. The failure mode he described is a SQL tool that takes a user ID argument and is meant to search only one tenant or one user. That argument can be tricked into arbitrary queries. If the conditions are hard-coded, the model has no user ID it can change.

Prompt injection needs a different control than SQL injection. With SQL, he said, escaping user input properly means zero risk. He added that people still get the escape wrong, which is why SQL injection attacks remain. A tool response becomes part of the prompt. It is not jailed, and it is not treated in any special way. You cannot make it safe in the sense of a 100% guarantee that the content was escaped. Sanitize inputs anyway, he said, while knowing those checks are hard to get right when an attacker can, say, write the prompt in Spanish. Treat every model-written part of the query as attacker-controlled, and hard-code the conditions so that text cannot widen access.

So the response of my tools become part of the prompt, period.

Malte Ubl, CTO at Vercel, on Chain of Thought ep 39

If instead I give the LM a tool that has hard coded what the conditions of the query is, then I cannot escape that.

Malte Ubl, CTO at Vercel, on Chain of Thought ep 39

A minimal sketch to adapt. db, call_model and the step fields are hypothetical; the point is that the tenant comes from the session and the model only supplies filter values.

def make_orders_tool(session):
    tenant_id = session.tenant_id  # from the authenticated session, never the model

    def find_orders(status, since):
        # fixed, parameterized query: the model supplies filters, not SQL
        return db.execute(
            "SELECT id, status, total FROM orders "
            "WHERE tenant_id = %s AND status = %s AND created_at >= %s",
            (tenant_id, status, since),
        )

    return find_orders


def run_agent(session, task, max_turns=10):
    find_orders = make_orders_tool(session)
    messages = [{"role": "user", "content": task}]
    for _ in range(max_turns):  # the whole budget, including the final answer
        step = call_model(messages, tools=[find_orders])
        messages.append(step.message)  # keep the model's tool request in history
        if step.finished:
            return step.output
        rows = find_orders(**step.args)
        messages.append({"role": "tool", "call_id": step.call_id, "content": str(rows)})
    return None  # out of turns: escalate instead of calling the model again

He called data exfiltration the other big problem. GitLab and GitHub, he said, had essentially the same vulnerability in short order. As he recalled it, attackers put prompt instructions in pull requests to public repositories, and the review tool's markdown comments could include images whose query strings carried the repository's source. His lesson was to treat the model's output as untrusted. In practice, restrict the URLs a comment tool can embed.

When should a human do the work and the model review it?

Have the human produce the work and the model review it. Malte calls that AI in the loop. Human in the loop means the model does the work and a person reviews it. He argues the inverse works well too, and gets less attention. He is a fan of AI code review because it does not forget past mistakes, it does not go to bed, and it does not wake up tired. He said people go low on quality the fifteenth time they repeat a tedious check.

A marketing language policy is his example. Those rules are hard to write as lint over natural language. An LLM can apply the written policy to each draft.

How do you debug a loop that picks its own path?

Add a trace of every tool call. The business rules live in the prompt, the model chooses its own path, and he said you need the trace because it changes from run to run.

Tool descriptions are prompt work. State what the tool is for, the argument signature, and the format of string arguments. He compared the model to a junior engineer with a lot of patience. Each call starts from scratch, so those notes are considered every time the program runs. Then add evals on a known task with known data, and assert the recommendation. Keep a judge model in the eval suite once the first pass is good, and skip the extra cost and latency on the live loop.

FAQ

Does the model have to use all 10 turns?
Malte would start with a turn count and stop when the model says it is done. The cap ends the loop if it is still calling tools.

Is a prompt filter enough to stop prompt injection?
Sanitize inputs. He encourages the check, and he said you still cannot guarantee a 100% escape. His example of a bypass is writing the instruction in Spanish. Put the tenant condition in the tool and take it from the session.

Where do evals fit after a vibe check?
The vibe check is one paste into a chat model before you build the loop. Evals run a known task on known data and assert the recommendation. He'd put the LLM judge in that suite rather than the live loop, which avoids the extra cost and latency once the agent gets it right on the first pass.

Takeaway

  • Ship the small loop first: a model, a trigger, a prompt, atomic tools, and a cap of 10 turns.
  • Stop when the model says the task is finished.
  • Read the tenant ID from the session inside the tool.
  • Treat tool results as prompt text and model-written query text as attacker-controlled.
  • Trace each run, add evals on known tasks, and use the judge model there. Put a judge in the live loop only if the first pass is not reliably right and the gain is worth the extra cost and latency.

The full conversation, with the transcript, is on Chain of Thought.

Subscribe to the Chain of Thought newsletter for new episodes and write-ups like this one.

Drafted with AI assistance from the episode transcripts.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.