Structured Output Compliance
The StructuredOutputCompliance metric allows you to verify whether a given LLM output is valid JSON and adheres to an expected schema. You can optionally provide a Pydantic schema to validate the structure and types of the fields.
How to use the StructuredOutputCompliance metric
You can use the StructuredOutputCompliance metric as follows:
Asynchronous scoring is also supported with the ascore method.
The
StructuredOutputCompliance score is 1 if the output is compliant, and 0 if it is not.Prompt Template
Opik uses an LLM as a Judge to evaluate the structural compliance. The default model used is gpt-4o, but this can be changed to any model supported by LiteLLM. You can learn more about customizing models in the Customize models for LLM as a Judge metrics section.
The prompt used by the LLM looks like this: