Skip to main content
All CollectionsWorkflowsAction Guides
Action: Format Structured Output
Action: Format Structured Output
Updated over a week ago

Overview

The Format Structured Output action enables you to transform raw data into a structured format like JSON based on a provided schema or instructions. This is useful for converting unstructured text, numbers, or other data types into an organized, machine-readable format that can be easily parsed and processed downstream in a workflow.

You can specify the desired output format (currently supporting JSON) as well as provide a custom schema or instructions for how the data should be structured. The action will intelligently map the input data to the requested output format, handling any necessary type coercion, nesting, or transformations. The output is a cleanly formatted JSON object that can be readily consumed by other actions or systems.

Usage Examples

  • Structure web-scraped data - After scraping raw text content from web pages using the HTTP Request action, you can pipe that unstructured data into this action to format it into a usable JSON structure with clear field names and hierarchy. This allows you to normalize scraped data into a consistent schema.

  • Format API responses - When making API calls, the response payload often comes back in an inconvenient structure or with extraneous fields. By defining the desired schema, you can use this action to extract and format only the relevant parts of the API response into a cleaner JSON output for use in the rest of your workflow.

  • Normalize user-inputted data - If you have a workflow that accepts free-form user input, such as from a form or survey, you can use this action to impose a consistent structure on that data. Specify the expected fields and data types, and the action will attempt to map the user-provided values into that schema.

Inputs

  • Format - The structured data format to convert the input to. Currently only JSON is supported.

  • Input Data - The raw input data to be converted to structured output. Can be unstructured text, numbers, or a mix of data types.

    • Try this sample text with the example schema below.

      Why should you never play poker at the zoo? Too many cheetahs
  • Schema of Your Output - A JSON schema that defines the desired structure of the output data. Specifies the expected fields, data types, nesting, and constraints. If provided, the action will attempt to fit the input data to this schema.

    • Example schema:

      {"joke":"the joke","punchline":"the punchline","analysis":"a description on why the joke is funny?"}

Outputs

The output of the Format Structured Output action is a JSON object or array representing the input data transformed into the requested structured format. The exact structure will depend on the provided schema.

The action aims to intelligently map input data to the specified output schema. Any input data or fields that don't fit the schema may be omitted from the output.

Troubleshooting

  • Unexpected output structure - If the output JSON doesn't match your expected structure, first double check that your provided schema or instructions are specifying the correct field names, types, and hierarchy. The action tries to map input fields to the output intelligently, but ambiguous instructions or data that looks like multiple types (e.g. a number inside a string) can lead to incorrect parsing. Try simplifying your schema or being more explicit in your instructions about how fields should be handled. Use precise language like "convert X to an integer" or "split Y on commas into an array".

Did this answer your question?