Hammurabi is an ancient ruler of Mesopotamia/Babylon who is famous for establishing a written code of laws, of which copies inscribed in steles have survived to this day). I don't know of it's the earliest example of a written legal code but certainly one of the earliest that we have a record of.
Among these laws were civil penalties for builders who performed shoddy workmanship:
> If a builder constructs a house for a man but does not make it conform to specifications so that a wall then buckles, that builder shall make that wall sound using his own silver.
By the way, the Romans also had building codes, and engineers who built bridges and roads were liable for the durability of those structures, thus a tradition of over-engineering.
> I don't know if it's the earliest example of a written legal code but certainly one of the earliest that we have a record of.
It isn't, but it was discovered early and benefited from intense popular interest in the Bible. Popular interest in Mesopotamian history fell off sharply as it turned out that history generally differed from what the Bible said.
It's still very early, roughly the 18th century BC.
>> If a builder constructs a house for a man but does not make it conform to specifications so that a wall then buckles, that builder shall make that wall sound using his own silver.
This is obviously a statement about who bears liability for fixing the wall, but it's funnier if you imagine it as a requirement for the builder to repair the wall with silver bricks, as a penalty for the original shoddy work.