> ## Documentation Index
> Fetch the complete documentation index at: https://nango.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Data validation

> How to validate data in your functions and in your app

Nango offers data validation at two levels: inside your [Nango functions](/guides/functions/functions-guide) (when calling external APIs) and in your application code (when consuming function responses).

## Validate API responses in Nango functions

Use Zod to validate data you receive from and send to external APIs. The CLI will also surface *type* errors during dry runs when using the `--validation` option.

```typescript theme={null}
import * as z from 'zod';

const dataFromAPI = z.object({
  ticketId: z.string(),
});

export default createSync({
  exec: async (nango) => {
    const response = await nango.get({ endpoint: '/tickets' });
    const isValid = dataFromAPI.parse(response.json);
    if (isValid) {
      [...]
    }
  },
});
```

## Validate Nango function responses in your app

### TypeScript types (compile-time)

Use `z.infer` to derive TypeScript types from your Zod schemas and export them from your sync/action files:

```ts theme={null}
// In: github/syncs/fetchIssues.ts (Nango function)
export type GithubIssue = z.infer<typeof issueSchema>;
```

Then import the types in your application code:

```ts theme={null}
import type { GithubIssue } from './nango-integrations/github/syncs/fetchIssues';

const issues = await nango.listRecords<GithubIssue>({ ... });
```

### JSON Schema (runtime, language-agnostic)

When you run `nango compile` or `nango deploy`, Nango generates a `nango.json` file in the `.nango` folder. Each sync/action entry includes a `json_schema` property with the JSON Schema for its models:

```json theme={null}
// .nango/nango.json (simplified)
[
  {
    "providerConfigKey": "github",
    "syncs": [
      {
        "name": "fetchIssues",
        "output": ["GithubIssue"],
        "json_schema": {
          "definitions": {
            "GithubIssue": {
              "type": "object",
              "properties": {
                "id": { "type": "string" },
                "title": { "type": "string" },
                "state": { "type": "string" }
              },
              "required": ["id", "title", "state"],
              "additionalProperties": false
            }
          }
        }
      }
    ]
  }
]
```

You can extract the `json_schema` object for a given sync or action and use it with any JSON Schema validator in your language of choice (e.g., `ajv` in TypeScript, `jsonschema` in Python, `jsonschema` in Rust, `santhosh-tekuri/jsonschema` in Go).

Alternatively, Zod v4 supports JSON Schema conversion natively with [`z.toJSONSchema()`](https://zod.dev/json-schema?id=ztojsonschema):

```ts theme={null}
import { z } from 'zod';
import { issueSchema } from './nango-integrations/github/syncs/fetchIssues';

const jsonSchema = z.toJSONSchema(issueSchema);
```

## Related guides

* [Action functions](/guides/functions/action-functions) - validate action inputs and outputs.
* [Sync functions](/guides/functions/syncs/sync-functions) - validate synced record models.
* [Unified APIs](/guides/functions/unified-apis) - normalize provider data behind stable schemas.
* [Testing](/guides/functions/testing) - cover validation behavior in tests.
