I wrote something like this, though not quite as slick, by having the model use json schema to describe its results instead of text, and then use a json-schema to ui interface.