Support For Structs in Function Backed Actions

Is this a thing that exists or will exist in the near future? I’m attempting to fit a wide variety of documents into a structured object that is a report. My current plan is to do an LLM call in AIP logic or Pipeline manager to put the text into a JSON. I have been able to create an object in my function in code repositories but when I integrate the action into AIP logic it fails because what is a struct is passed as a string.

Scott

2 Likes

Hello! Apologies for the delay in response -

Structs are supported in TSv2 Functions - we’ve updated the docs here: https://www.palantir.com/docs/foundry/functions/typescript-v2-ontology-edits/#edits-on-struct-properties

When creating a Function-Backed Action for a function that takes a struct input, an Actions struct parameter mapped to the Functions struct input will be automatically created.

For instance, creating a function-backed action for the following function:

interface Address {
    street: string,
    city: string,
    state: string,
    country: string,
    zipcode: string,
}

function createPerson(client: Client, age: Integer, name: string, address: Address) {
    ...
}

will generate a struct parameter in the action type that maps directly to the address function input.

The following would be an example of a function that edits an object type struct property:

import { Person } from "@osdk/generated";
import { createEditBatch, Edits, EditBatch } from "@osdk/functions"
import { Integer } from "@osdk/functions";
import { Client } from "@osdk/client";

type CreatePersonEdit = Edits.Object<Person>;

interface Address {
    street: string,
    city: string,
    state: string,
    country: string,
    zipcode: string,
}

function createPerson(
    client: Client, age: Integer, name: string, address: Address
): CreatePersonEdit[] {
    let editBatch: EditBatch<CreatePersonEdit> = createEditBatch<CreatePersonEdit>(client);
    editBatch.create(Person, {name: name, age: age, address: address});
    return editBatch.getEdits();
}

export default createPerson;

The struct value submitted as the value for the address struct property can also be constructed within the function - it just needs to be a typescript interface value that contains the field names that correspond to the struct field API names of the ontology struct property. Assuming the address struct property has the struct field with the API names street, city, state, country, zipcode, the following example would also work:

function createPerson(
    client: Client, age: Integer, name: string, street: string, city: string
): CreatePersonEdit[] {
    let editBatch: EditBatch<CreatePersonEdit> = createEditBatch<CreatePersonEdit>(client);
    let address = {
        street: street,
        city: city,
        state: "NY",
        country: "USA",
        zipcode: "12345"    
    };
    editBatch.create(Person, {name: name, age: age, address: address});
    return editBatch.getEdits();
}

Thank you so much for your help. I was able to use this to finish my project.