The Langchain package does something similar to this and has a feature to combat that kind of thing that basically feeds the invalid input back into the bot and says “you were asked for x but gave this, please correct it” - it’s shockingly effective.