Urgent.News

What's breaking now, across thousands of outlets.

AI

Turning a labour law into tested TypeScript: what an AI pair taught me about legal code

I run a small free site of UAE pay and labour calculators. I'm not a lawyer, and most of the code was written with Claude Code (Anthropic's coding agent) while I directed it. This post was also drafted with its help and checked by me. What I want to share is the process we settled on, because "AI writes a gratuity calculator" goes wrong in very specific ways. The problem UAE end of service…

This story details the process of creating AI-powered gratuity calculators for UAE workers while ensuring strict adherence to the legal code. The author, who is not a lawyer, used Claude Code (Anthropic's coding agent) to help draft the calculators. The key lessons learned are:

1. The UAE end of service gratuity calculation is more complex than commonly perceived, with multiple articles in the Federal Decree-Law No. 33 of 2021 governing the rules. No rule should be included in the code unless it is directly sourced from the official text.

2. Separating the law from conventions helps differentiate between legal requirements and commonly used conventions. The code includes a separate list of conventions, such as the daily wage calculation, to keep them distinct from legal rules.

3. Every test case should be worked out by hand to ensure accuracy. The author emphasizes that AI should not be allowed to generate test values through the function itself, as this would lead to incorrect results. The tests includes arithmetic calculations to verify the correctness of the implementation.

4. Date calculations are particularly prone to errors when using simple division by 365. The author implemented a function to calculate the exact number of years between two dates, accounting for leap years and ensuring the correct result in all cases.

5. Finally, the author stresses the importance of documenting what is not modeled in the calculator. Part-time workers and potential deductions by employers are not included in the current version, but this is clearly stated in the module header and on the page. Being upfront about limitations is better than silently ignoring certain cases.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in AI

Multiple LLM Providers: One API Key With Observable Candidate-Scoring Fallback

A media company puts multiple LLM providers behind one API key for candidate scoring, then the overnight page says its text-classification queue is late.

  • Media outlet uses multiple LLM providers with single API key
  • Invalid classifications observed despite successful API requests
  • Emphasizes need for portable JSON contract and validation

More from Saturday 3 October →