Add validity checking for Inspect.Algebra documents

Fix for #1687.