So even having a bulletproof confidentiality agreement prepared by a lawyer is only enforceable against parties to the contract. And if your idea is leaked to a third party, or someone that didn't even sign the agreement. You have no recourse. As such, it's best to use a non-disclosure agreement as a second line of defense, and only after a patent application has already been filed.
Now, when Zhang Doe sues Bil's Bagel factory for breach of contract, what happens? Bil's Bagel factory will have a valid defense. They have no contract with Zhang Doe. In fact, they can legitimately say that they never spoke to Zhang Doe, never corresponded with him, never met him, and have absolutely no idea who Zhang Doe is. In most cases, it will be virtually impossible for Zhang Doe to trace and prove that the idea that Bil's Bagel factory is using originated with him.
But what if the people at Joe's Bagel factory are smart enough not to take the idea. Let's take this scenario from the beginning. Joe's bagel factory signs a contract with Zhang Doe. This is the confidentiality non-disclosure agreement. Zhang Doe then explains his idea to Joe's Bagel factory. The folks at Joe's Bagel factory are smart enough not to steal the idea themselves. So they simply leak the idea to an affiliated company of theirs, or perhaps a close friend, or even an acquaintance, let's call them Bil's Bagel factory.
How do inventor confidentiality agreements work. Well, suppose inventor Zhang Doe comes up with a new way of making bagels. He wants to sell his idea to Joe's Bagel factory. Now, Zhang Doe can ask Joe's Bagel factory to sign an agreement called a confidentiality or non-disclosure agreement. Often abbreviated as an NDA. This is an agreement where Joe's Bagel factory will agree to review Zhang Doe's idea, and keep it a secret.
Typically, Joe's Bagel factory will also promise not to use the idea without first paying Zhang Doe. If Joe's Bagel factory is honest, Zhang Doe has nothing to worry about. But what if Joe's Bagel factory wants to steal the idea, and not pay Zhang. After the lawsuit, Zhang Doe would be entitled to a judgment for money damages to compensate him for Joe's Bagel factory breaking the contract.