Coding with AI Is a Copyright Risk

When coding with AI you're incurring the risk of violating copyright.

Whatever you think of programming with AI, it seems inevitable that we will all use AI for programming in some form soon if we don’t already. Beyond the philosophical questions (“did I create this code or did the AI”?), we let an LLM create some code and the assert that we own that code. But do we really or are do we risk getting in trouble with copyright law?

What’s the Problem?

The actual copyright risk with AI code is that the generated code may reproduce code that is owned by someone else. That means we cannot use the code without the permission of the copyright holder.

But how could such code end up in the LLM’s output? The first way is pretty obvious: LLM’s can search the internet these days, so it could easily find some source file and incorporate it in its output. You can try to control this by prompting, but since we don’t know how to control what the LLM does algorithmically, we cannot be sure there’s no direct copying of this kind going on.

The second way is that the copyrighted code was used as training data and that the LLM recreates the code from it’s stored weights. It’s legally unclear whether just training model on some code already activates the license clauses of the code. What is very clear, though, is that “the AI wrote it” is not a valid defense in a copyright suit. If you end up with copyrighted code, you do need a license to use it.

The third case is that the generated code was not in the training data, but that the LLM creates an exact copy of the copyrighted code from the general knowledge of programming it gained in training.

In practice, it’s very hard to distinguish cases 2 and 3, but for you as a user, the distinction does not matter anyway.

So What Could Happen?

So let’s assume that you end up using someone else’s code in your product. The owner of that code can now go to the courts and demand two things: first, that the illegal use of the copyrighted material is rectified. This can happen in two ways, either you stop using the code or you acquire a license for that code from the copyright owner. In some cases, this can be very simple: if the code is under MIT license, for example, you simply have to maintain the original copyright notices and make the licensed code readily available. In the case of proprietary code, you usually have to sign a contract with the copyright holder and pay a license fee. The second consequence of a copyright violation is that the copyright holder can demand compensation for your unlicensed use of the code. While we hear about the big ticket cases, where billions of dollars are demanded in damages, the claimant has to demonstrate in court that he has actually incurred any damages at all. It’s hard to argue that you owe a million bucks if all you did was use a simple script on your mom’s personal website. The bigger problem is the litigation itself: if you are a SME in Switzerland, a lawsuit in a Delaware court against an American corporate giant can quickly become dangerously expensive.

How Can I Protect Myself?

One way to reduce your risk is trying to detect that the AI has generated copyrighted code. There are services that can automate this process. For example, the Theia IDE has support for the SCANOSS service built in: you can just push a button and the service will tell you whether the code comes from one of the repositories they track. Using such a service can help you in two ways: first, you can make sure you are complying with the applicable open source licenses. But there is also legal value in checking against existing code. If you can demonstrate you did your due diligence, damages in a lawsuit are often reduced.

The obvious problem with this approach is that you can only check for copying against the code that these services can acutally see. Much proprietary code is not publicly available. Since the big LLM players will not make their training sets public, we just have their word that everything is on the level. But recent reports in the press about training on unlicensed material makes me doubt those promises.

Some AI vendors also offer indemnification clauses in their contracts. What they usually promise is that they would help you fight any copyright claims against generated code and that they would come up for any damages you’d have to pay. What such contract clauses cannot do is transform copyrighted code into public domain: you’d still have to stop using the code or aquire a license. These indemnification clauses are also largely untested in the real world. There are usually conditions attached to the contracts. The AI vendor might well decide that it’s cheaper to challenge your claim to indemnification than the copyright suit.

In Conclusion

The risk of introducing copyrighted material into your codebase by using AI is real. While you can migitate the legal and technical risks, you cannot eliminate them completely. However, theses risks are usually not existential if you follow good practices. Companies are already managing risks from using dependencies, open source license and patents. AI coding just adds one more category. It’s just a cost of doing business in an AI world.