I don't recall the name of the app, but drawing formulas, equations etc with a finger was a thing on Android like 10 years ago. And it did things like a mix of fractions and square roots etc just fine.
Assume words don't contain numbers and numbers don't contain words, then provide a convenient UI for selecting alternatives?
For fielded input matching known patterns, recognition can also be constrained by pattern matching and general validation rules (e.g., VINs are 17 characters long, cannot contain the letters I, O, or Q, and, given prior information in other fields, can be further constrained by manufacturer code, model year, and by requiring a correct check digit).