Structured Output Response

Structured output is a feature that allows large language models (LLMs) to generate responses in a specific format with your resources. Structured output is best for extracting structured data to fit your application’s needs. It returns data formatted with the json_schema and json_schema_rules you provide. To use the structured output feature you need to provide the following parameters:

ParameterTypeDescription
collection_idStringThe unique ID of the collection to query.
request_queryStringThe search term or query text.
json_schemaStringThe desired structure for the JSON response.
json_schema_rulesStringCustom rules to guide the response’s adherence to the specified JSON schema.

json_schema

The json_schema parameter defines the structure of the response you want the system to return. This parameter helps ensure the output matches your application’s requirements.

Example JSON Schema

{
    "topic" : "string",
    "description" : "string",
    "description" : "int"
}

Example JSON Schema (List)

If you want a list of items and not just a single item, you can specify the json schema by putting the entire object in a list

[
  {
    "topic" : "string",
    "description" : "string",
    "description" : "int"
  }
]

json_schema_rules

The json_schema_rules parameter allows you to define custom rules for how the schema is applied. Another way to think about this is that it is a set of instructions for the LLM to follow when generating the response. This can also be in form of a more detailed prompt This can include constraints on the data, additional formatting, or validation logic.


Example Requests

curl --request POST \
 --url 'https://api.wetrocloud.com/v1/query/' \
 --form 'collection_id=<collection_id>' \
 --form 'request_query=What is this about?' \
 --form 'json_schema=[{"topic":"","description":""}]' \
 --form 'json_schema_rules=Give a very short description of every page on the document from' \
 --header 'Authorization: Token <api-key>'

Example Response

{
   "response": [
       {
           "topic": "Introduction to Corporate Bonds",
           "description": "An overview of what corporate bonds are and their significance in the investment landscape."
       },
       {
           "topic": "How Corporate Bonds Work",
           "description": "Explanation of the mechanics of corporate bonds, including issuance, interest payments, and maturity."
       },
       {
           "topic": "Types of Corporate Bonds",
           "description": "Discussion of various types of corporate bonds, such as investment-grade and high-yield bonds."
       },
       {
           "topic": "Risks Associated with Corporate Bonds",
           "description": "Insight into the risks involved in investing in corporate bonds, including credit risk and interest rate risk."
       },
       {
           "topic": "Benefits of Investing in Corporate Bonds",
           "description": "Highlighting the advantages of corporate bonds, such as income generation and portfolio diversification."
       },
       {
           "topic": "Corporate Bond Market Overview",
           "description": "A look at the corporate bond market, including market size, participants, and trends."
       },
       {
           "topic": "How to Invest in Corporate Bonds",
           "description": "Guidance on the methods and platforms available for investing in corporate bonds."
       },
       {
           "topic": "Conclusion",
           "description": "Summary of key points regarding corporate bonds and their role in investment strategies."
       }
   ],
   "tokens": 4007,
   "success": true
}
FieldDescription
responseJSON object structured as per the provided schema.
tokensNumber of tokens used for processing.
successIndicates whether the query was successful.