trpc/trpc · error · Error
Greeting not found
Error message
Greeting not found
What it means
A documentation example (output-validation.md, v9) using tRPC v9's router().query() API with a custom output validator. It throws 'Greeting not found' when the returned value does not have a string greeting property, showing how to validate resolver output in tRPC v9 before schema libraries were the default.
Source
Thrown at www/versioned_docs/version-9.x/server/output-validation.md:102
});
export type AppRouter = typeof appRouter;
```
### With custom validator
```tsx
import * as trpc from '@trpc/server';
import * as t from 'superstruct';
// [...]
export const appRouter = trpc.router<Context>().query('hello', {
output: (value: any) => {
if (value && typeof value.greeting === 'string') {
return { greeting: value.greeting };
}
throw new Error('Greeting not found');
},
// expects return type of { greeting: string }
resolve() {
return { greeting: 'hello!' };
},
});
export type AppRouter = typeof appRouter;
```
View on GitHub (pinned to acff82332d)
Solutions
- Ensure resolve() returns { greeting: string }.
- Replace the custom validator with a zod/superstruct schema for the output.
- Update the validator if the resolver contract intentionally changed.
Example fix
// before: resolver returns wrong shape
resolve() { return { message: 'hi' }; }
// after: match the validated shape
resolve() { return { greeting: 'hello!' }; } Defensive patterns
Strategy: validation
Validate before calling
// Validate the resolver output before relying on it
function hasGreeting(v: unknown): boolean {
return typeof v === 'object' && v !== null && typeof (v as any).greeting === 'string';
} Type guard
function isGreetingObj(v: unknown): v is { greeting: string } {
return typeof v === 'object' && v !== null && typeof (v as any).greeting === 'string';
} Prevention
- Use zod/superstruct for output in v9 to align types and validation.
- Unit-test the resolver against the output contract.
- Migrate custom output validators to schemas when upgrading.
When it happens
Trigger: The hello resolver returns a value without a string greeting property (e.g. null, {}, { greeting: 123 }), so the output validator throws.
Common situations: Resolver return shape drifting from the validator; migrating from v9 and forgetting to update the output check; returning undefined from resolve().
Related errors
- Output is not a string
- Invalid input: ${typeof val}
- Input is not a string
- Invalid input: ${typeof val}
- BAD_REQUEST
AI-assisted analysis of trpc/trpc@acff82332d (2026-08-12).
Data as JSON: /api/errors/b0c27a7a02ccf3e5.
Report an issue: GitHub.