Hacker News new | past | comments | ask | show | jobs | submit login

LLMs are extremely poor at following negative instructions, tell them what to do, not what not to do.



Ok, so saying "Implement feature X" leads to a ton of comments. How do you rewrite that comment to not include "don't write comments" while making the output not containing comments? "Write only source code, no plain text with special characters in the beginning of the line" or what are you suggesting here in practical terms?


“Constrain all comments to a single block at the top of the file. Be concise.”

Or something similar that does not rely on negation.


I also include something about "Target the comments towards a staff engineer that favors concise comments that focus on the why, and only for code that might cause confusion."

I also try and get it to channel that energy into the doc strings, so it isn't buried in the source.


But I want no comments whatsoever, not one huge block of comments at the top of the file. How'd I get that without negation?

Besides, other models seems to handle negation correctly, not sure why it's so difficult for the Gemini family of models to understand.


This is sort of LLM specific. For some tasks you might try including the word comment but give the order at the beginning and end of the prompt. This is very model dependent. Like:

Refractor this. Do not write any comments.

<code to refractor>

As a reminder your task is to refractor the above code and do not write any comments.


> Do not write any comments. [...] do not write any comments.

Literally both of those are negations.


Yes my suggestion is that negations can work just fine, depending on the model and task, and instead of avoiding negations you can try other promoting strategies like emphasizing what you want at the beginning and at the end of the prompt.

If you think negations never work tell Gemini 2.5 to "write 10 sentences that do not include the word the" and see what happens.


"Implement feature X, and as you do, insert only minimal and absolutely necessary comments that explain why something is being done, not what is being done."


You would say "omit the how". That word has negation built in.


"Whenever you are tempted to write a line or block comment, it is imperative that you just write the actual code instead"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: