Documentation Index
Fetch the complete documentation index at: https://docs.promptlayer.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
When logging requests that use structured outputs (JSON schemas), you need to include the schema configuration in theparameters field of your /log-request call. This allows PromptLayer to properly track and display your structured output configurations alongside your request history.
When to Use This
Use structured output logging when you’re:- Making API calls with JSON schema validation (OpenAI, Anthropic, Google, etc.)
- Tracking requests that enforce specific response formats
- Analyzing how different schema configurations affect model outputs
- Building applications that require reliable, parseable JSON responses
Basic Structure
The structured output configuration goes in theparameters field of your log request, using the response_format key with json_schema configuration:
Complete Examples
OpenAI with Structured Outputs
Google Gemini with Structured Outputs
JavaScript/TypeScript Example
REST API Example
If you’re calling the/log-request endpoint directly via REST API:
Schema Configuration Details
Key Fields
name(required): A descriptive name for your schema (e.g., “Recipe”, “ContactInfo”)description(optional): Explains what the schema representsschema(required): The actual JSON schema definition following JSON Schema specificationstrict(optional): Whentrue, enforces strict validation (supported by some providers like OpenAI)
Schema Best Practices
- Use clear property names: Make your schema self-documenting
- Specify required fields: Use the
requiredarray to mark mandatory properties - Set
additionalProperties: false: Prevents unexpected fields in the response - Use descriptive types: Leverage JSON Schema’s type system (string, number, array, object, boolean)
- Add validation constraints: Use
minLength,maxLength,minimum,maximum, etc. when appropriate
Tracking Schema Variations
Use tags and metadata to track different schema versions:Common Issues and Solutions
Issue: Schema not showing in PromptLayer dashboard
Solution: Ensure theresponse_format is nested correctly within the parameters field, not at the top level of your log request.
Issue: Provider rejects the schema
Solution: Different providers have different schema support levels:- OpenAI: Full support with
strict: truemode - Anthropic: Supports basic JSON mode
- Google: Supports schemas with some limitations
Issue: Response doesn’t match schema
Solution:- Verify your schema is valid JSON Schema
- Test with
strict: trueif your provider supports it - Check that your prompt clearly instructs the model about the expected format
- Review logged requests in PromptLayer to debug schema mismatches
See Also
- Structured Outputs in Prompt Registry - Creating prompts with structured outputs
- Custom Logging Guide - General guide to logging requests
- Log Request API Reference - Full API specification
- Metadata Documentation - Using metadata for tracking
- Tagging Requests - Organizing requests with tags

