As artificial intelligence infiltrates public decision-making, the very foundations of democratic legality face an unprecedented stress test.