What prompts would one give an LLM if one was seeking to generate a test dataset based on a JSON Schema. I'm particularly interested what sort of additional documentation would make the test dataset most effective.. Use Case documents explaining the business rules and relationships between things in the domain model?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Great question! When generating a test dataset based on a JSON Schema using a large language model (LLM), the quality and usefulness of the dataset depend heavily on the prompts you provide and the supplementary documentation you include. Here’s a detailed breakdown:
1. What Prompts to Give an LLM for Generating Test Data from JSON Schema
Basic Prompt Structure
Input: JSON Schema (or a summary of it)
Task: Generate valid test data instances conforming to the schema
Example prompt:
code
Given the following JSON Schema, generate 10 example JSON objects that conform to this schema:
<insert JSON Schema here>
Enhancing the Prompt for Better Data
Ask for varied data to cover edge cases:
code
Generate 10 example JSON objects that conform to this schema, including typical values, boundary values, and some edge cases.
Request invalid examples for negative testing:
code
Generate 5 invalid JSON objects that violate this schema in different ways.
Specify data diversity:
code
Generate examples with diverse values for each field, including nulls, empty strings, and maximum length strings where applicable.
2. Additional Documentation to Make the Test Dataset Most Effective
a. Use Case Documents / Business Rules
Why: JSON Schema defines structure and basic constraints (types, required fields, formats), but it often lacks domain-specific logic.
What to include:
Business rules: e.g., "If status is 'active', then activationDate must be present and in the past."
Field relationships: e.g., "The endDate must be after the startDate."
Conditional logic: e.g., "If paymentMethod is 'credit card', then cardNumber must be present and valid."
Enumerations and allowed values: Sometimes the schema uses generic strings, but business rules restrict values further.
Data dependencies: e.g., "If country is 'US', then state must be one of the 50 US states."
b. Domain Model Explanation
Why: Helps the LLM understand the context and semantics behind fields.
What to include:
Descriptions of entities and their relationships.
Typical workflows or scenarios where the data is used.
Examples of real-world data or sample records.
c. Data Distribution and Frequency
Why: To generate realistic datasets that reflect production data.
What to include:
Expected value distributions (e.g., 70% of users are active, 30% inactive).
Typical ranges for numeric fields.
Common vs rare values.
d. Constraints Beyond Schema
Why: Some constraints cannot be expressed in JSON Schema (e.g., uniqueness across dataset).
What to include:
Uniqueness constraints (e.g., userId must be unique).
Referential integrity (e.g., foreign keys).
Temporal constraints (e.g., timestamps must be within last year).
3. Example of a Rich Prompt Combining All Elements
code
You are a data generator. Given the following JSON Schema and business rules, generate 20 JSON objects that conform to the schema and rules.
JSON Schema:
<insert schema>
Business Rules:
- If "status" is "active", "activationDate" must be present and before today.
- "endDate" must be after "startDate".
- "paymentMethod" can be "credit card", "paypal", or "bank transfer".
- If "paymentMethod" is "credit card", "cardNumber" must be a valid 16-digit number.
- "country" is either "US" or "Canada". If "US", "state" must be one of the 50 US states; if "Canada", "province" must be one of the 10 provinces.
- "userId" must be unique across all generated objects.
Please include a mix of typical, boundary, and edge cases.
Summary
Prompts: Start with schema + request for valid examples, then add requests for edge cases, invalid data, and diversity.
Documentation: Provide detailed business rules, domain model explanations, data distributions, and constraints beyond schema.
Result: The LLM can generate realistic, comprehensive test datasets that not only validate schema conformance but also test business logic and real-world scenarios.
If you want, I can help you draft specific prompts or even generate sample datasets based on your schema and rules!