3 ms·
Ask HN: How do you guys stop coding agents from acting out of line?
I’ve been pretty annoyed recently with my coding agents doing stupid things that are anti-protocol. I can encode rules like “agents shouldn’t write to the README” pretty easily, but things like “database migrations must be autogenerated and not handwritten” are much harder to enforce. Anyone have any tools they use for this or tips for how to deal with issues like that?
- deleted 3mo ago[deleted]
- biemone 3mo ago[dead]
- laruss5 3mo ago[flagged]
- gabosarmiento 3mo agoHave you consider asking your agent to set up basic permission deny rules to block dangerous commands? Just ask it and request that it shows you the config before applying it.
- vivekyyy 3mo agoI can add some basic configs, but it seems kinda provider dependent, so I'm gonna need to do this differently for Claude, Cursor, and Codex. It will also require a custom pre-tool use plugin to allow something like "AI can generate DB migrations via CLI but cannot handwrite them", which is pretty annoying when I need a separate one per model
- ReadyAgents 3mo ago[dead]
- chachachainsaw 3mo agoSome of the configs are fairly similar, and if you bundle in a plugin they can be distributed without much ceremony. Something you can do for forcing cli migration generation is to write a pretool hook. Here’s an example of shared hooks. https://frontmatter.news/kinds/hook https://frontmatter.news/kinds/hook This website also has markdown versions of pages and references source docs so you can point your agent to the page and ask it to crawl to the docs pages to reference the hook json definition.
- deleted 3mo ago[deleted]
- entity002 3mo ago[flagged]
- jryan49 3mo agoTelling llms what not to do actually makes things worse. Frame things in positive language where possible, if not possible I don't mention it at all. The biggest fix for me is using better models. You can't rely on guardrails to make dumber models act smarter.
- dearlinko 3mo ago[flagged]
- dylanratcliffe 3mo agoIt's often easier to catch and scold them than to prevent it. We have rule for example that agents (or anyone) can't touch autogenerated code. They still routinely do, but there is a CI job that re-generates everything and fails if there is a diff. Which the agents then see and fix. We have also use hooks for the same thing since they run locally and the feedback cycles are shorter.
- vivekyyy 3mo agoThis is possible, but I just kinda feel like at that point I should just generate the migrations in CI. The point of having them out of CI (for me at least) was so we can manually write in upgrade/downgrade logic when the autogenerated migration is a little off
- chachachainsaw 3mo agoI use a lot of agent hooks to force deterministic guardrails in the moment for faster feedback loops, like someone else mentioned. Others like pre-commit hooks and CI checks are still great for things like enforcing conventional commits, linting, etc. What framework do you use for generating migrations? I can help share an example of what it might look like to write a hook for it. Or even your top 3 pain points.
- vivekyyy 3mo agoWe use alembic for it, kinda curious what a hook config would look like here. Alembic files are pretty nice because they basically specify what sections of the revision should and shouldn't be manually edited, but agents routinely just ignore that lol