Source: pp 229-230, Thinking Like a Lawyer: An Introduction to Legal Reasoning (2010, 2 ed) by Kenneth J. Vandevelde.
The statute granting federal question jurisdiction to the district courts has been limited by a judicially created rule known as the “well-pleaded complaint” rule.19 Under this rule, the federal question must be a necessary part of the plaintiff ’s complaint. That is, a federal question raised by a defense does not bring the case within federal subject matter jurisdiction.
For example, assume that a retail store sues a manufacturer for breach of contract because the manufacturer failed to ship some toys that the retail store had ordered. The manufacturer raises as its sole defense the fact that after the order was placed, the federal government issued regulations banning this type of toy. Although the result in the case may well depend on an interpretation or application of the federal toy regulation, that federal law was raised as part of a defense and not as a necessary part of the plaintiff ’s claim. The plaintiff ’s claim was for breach of contract and could be set forth in its entirety without ever mentioning the toy regulation. Thus, under the well-pleaded complaint rule, the court probably would not have federal question jurisdiction over the retailer’s claim.
19 See Louisville & Nashville Railroad Company v. Mottley, 211 U.S. 149 (1908). [OP: I have already read this case.]
How is the bolded possible and realistic? Surely the plaintiff's counsel would expect and then anticipate the defendant's attempt to exculpate the defendant by deflecting all liability onto the federal government's law that bans the toys? Then:
The plaintiff would have engaged federal law in his cause of action.
The plaintiff’s claim for breach of contract needs to mention the toy regulation.