> No because if I add space to the original string I don't get a valid string
Yeah, it's telling you what it was expecting when it hit an invalid token.
You take the invalid part and filter the list of suggestions with it. If you tell chatgpt about the problem it solves it.
(Edit - when I was running this, having any number of spaces was parsed as valid btw if that's the concern - space was a valid option)