Petit taxis (small, city-only taxis, usually beige, blue, or red depending on the city) are legally required to run a meter — ask for it with "compteur, s'il vous plaît" when you get in. If the driver claims it's broken, it's simplest to just agree on a fixed price before departure, or switch to another taxi.
Grand taxis (shared, older Mercedes sedans that run set intercity routes) don't use meters at all — the price per seat is fixed and locally known, so ask your riad or hotel what the going rate is before you negotiate, and never pay before you've actually arrived. This one habit — agree first, pay after — avoids the vast majority of taxi disputes tourists run into.