QuestionQ108

Prompt Engineering & Structured Output

You are developing a structured data-extraction system using Claude. The system extracts information from unstructured documents, validates output with JavaScript Object Notation (JSON) schemas, and maintains high accuracy. It must gracefully handle edge cases and integrate with downstream systems.

Your extraction uses tool use with a JSON schema in which property_type is defined as an enum: ['house', 'apartment', 'condo', 'townhouse']. After deployment, 8% of extractions fail schema validation. Investigation shows that listings mention many uncommon property types—"studio", "loft", "duplex", "mobile home", "tiny house", "converted warehouse"—and new types continue to appear regularly.

What is the most effective long-term solution?

Explanation

An other enum value with a companion detail field keeps property_type within a stable, schema-valid set for downstream consumers while preserving the specific unrecognized property type. This handles an evolving, open-ended set of legitimate values without forcing inaccurate mappings or continuously expanding the controlled enum. Claude tool schemas define the expected structured input shape, so this design retains the benefits of schema-constrained output while accommodating edge cases.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!