# `LangChain.FunctionParam`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.0/lib/function_param.ex#L1)

Define a function parameter as a struct. Used to generate the expected
JSONSchema data for describing one or more arguments being passed to a
`LangChain.Function`.

Note: This is not intended to be a fully compliant implementation of
[JSONSchema
types](https://json-schema.org/understanding-json-schema/reference/type). This
is intended to be a convenience for working with the most common situations
when working with an LLM that understands JSONSchema.

Supports:

* simple values - string, integer, number, boolean
* enum values - `enum: ["alpha", "beta"]`. The values can be strings,
  integers, etc.
* array values - `type: :array` couples with `item_type: "string"` to express
  it is an array of.
  * `item_type` is optional. When omitted, it can be a mixed array.
  * `item_type: "object"` allows for creating an array of objects. Use
    `object_properties: [...]` to describe the structure of the objects.
* objects - Define the object's expected values or supported structure using
  `object_properties`.

The function `to_parameters_schema/1` is used to convert a list of
`FunctionParam` structs into a JSONSchema formatted data map.

## Examples

Basic string field.

    FunctionParam.new!(%{name: "name", type: :string})

Basic string field with description

    FunctionParam.new!(%{name: "name",
                         type: :string,
                         description: "User's name"})

Basic required string field with description

    FunctionParam.new!(%{name: "name", type: :string, required: true})

Required boolean field with description

    FunctionParam.new!(%{name: "active", type: :boolean, required: true})

A string Enum field. The field's value can only be one of the values specified
by the enum.

    FunctionParam.new!(%{name: "color",
                         type: :string,
                         enum: ["red", "yellow", "blue"],
                         description: "The specified primary color})

Array of strings field example. Defines a set of tags that an LLM may assign.

    FunctionParam.new!(%{name: "tags", type: :array, item_type: "string")

A field that represents an object with nested fields.

    FunctionParam.new!(%{name: "person",
                         type: :object,
                         object_properties: [
                           FunctionParam.new!(%{name: "name", type: :string, required: true}),
                           FunctionParam.new!(%{name: "age", type: :integer}),
                         ]
                      })

# `t`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.0/lib/function_param.ex#L90)

```elixir
@type t() :: %LangChain.FunctionParam{
  description: term(),
  enum: term(),
  item_type: term(),
  name: term(),
  object_properties: term(),
  required: term(),
  type: term()
}
```

# `new`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.0/lib/function_param.ex#L107)

```elixir
@spec new(attrs :: map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
```

Build a new FunctionParam struct.

# `new!`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.0/lib/function_param.ex#L118)

```elixir
@spec new!(attrs :: map()) :: t() | no_return()
```

Build a new `FunctionParam` struct and return it or raise an error if invalid.

# `required_properties`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.0/lib/function_param.ex#L205)

```elixir
@spec required_properties(params :: [t()]) :: [String.t()]
```

Return the list of required property names.

# `to_json_schema`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.0/lib/function_param.ex#L236)

```elixir
@spec to_json_schema(data :: map(), t()) :: map() | no_return()
```

Transform a `FunctionParam` to a JSONSchema compatible definition that is
added to the passed in `data` map.

# `to_parameters_schema`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.0/lib/function_param.ex#L222)

```elixir
@spec to_parameters_schema([t()]) :: %{required(String.t()) =&gt; any()}
```

Transform a list of `FunctionParam` structs into a map expressing the structure
in a JSONSchema compatible way.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
