Rule
0 installs · 0 said it worked
Cursor rules that stop AI from generating hallucinated NestJS code
A Cursor rules file that makes the assistant check generated NestJS code against banned phantom imports, deprecated patterns, unsafe types, and config and database pitfalls before emitting it.
People use this for
- nestjs code generation rules
- cursor nestjs hallucination guard
- avoid deprecated nestjs patterns
- check nestjs imports before generating code
- generate nestjs code without phantom packages
- Name
cursor-rules-that-stop-ai-from-generating-hallucinated-nestjs-co- Works with
- Cursor
- License
- CC0(as observed at the source)
- Version
- v1 · updated Nov 29, 2026
Imported on Nov 29, 2026 from github.com . License observed at the source on Nov 29, 2026: CC0.
Are you the author?Claim this profileRequest removal
Use this rule
$ curl -fsSL "https://promptcommunity.dev/api/v1/posts/cursor-rules-that-stop-ai-from-generating-hallucinated-nestjs-code-7j5y/export/mdc" -o .cursor/rules/cursor-rules-that-stop-ai-from-generating-hallucinated-nestjs-co.mdcThen open a new session; Cursor picks it up from .cursor/rules/.
Manual install
Save cursor-rules-that-stop-ai-from-generating-hallucinated-nestjs-co.mdc as .cursor/rules/cursor-rules-that-stop-ai-from-generating-hallucinated-nestjs-co.mdc for this project or ~/.cursor/rules/cursor-rules-that-stop-ai-from-generating-hallucinated-nestjs-co.mdc for every project, then start a new session.
Rule
description: "Cursor rules that block deprecated, phantom, or incorrect NestJS imports, decorators, providers, modules, and testing patterns." globs: */ alwaysApply: false
NestJS Anti-Hallucination Rules
These rules OVERRIDE all other generation behavior. Check EVERY line of generated code against these rules.
Banned Imports & Phantom Packages
NEVER import these — they don't exist or are deprecated:
❌ @nestjs/core/decorators — not a real export path
❌ @nestjs/swagger/decorators — import from @nestjs/swagger directly
❌ @nestjs/typeorm/repository — not a real export path
❌ @nestjs/passport/strategies — import from passport-jwt, passport-local, etc.
❌ @nestjs/bull/decorators — import from @nestjs/bullmq (bull is legacy)
❌ nestjs-redis — use @nestjs-modules/ioredis or ioredis directly
❌ @nestjs/cqrs/decorators — import from @nestjs/cqrs directly
❌ nestjs-config — use @nestjs/config (official)
❌ nestjs-pino/logger — import from nestjs-pino directly
Correct import paths:
// ✅ Swagger
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
// ✅ TypeORM
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, DataSource } from 'typeorm';
// ✅ BullMQ (NOT Bull)
import { InjectQueue, Processor, WorkerHost } from '@nestjs/bullmq';
// ✅ Config
import { ConfigService, ConfigModule } from '@nestjs/config';
// ✅ Passport
import { AuthGuard } from '@nestjs/passport';
import { Strategy as JwtStrategy, ExtractJwt } from 'passport-jwt';
// ✅ CQRS
import { CommandHandler, ICommandHandler, EventBus } from '@nestjs/cqrs';
Deprecated Patterns — NEVER Generate These
1. getRepository() outside providers
// ❌ DEPRECATED — removed in TypeORM 0.3+
const repo = getRepository(User);
const user = await getConnection().getRepository(User).find();
// ✅ CORRECT — inject via constructor
constructor(
@InjectRepository(User)
private readonly userRepo: Repository<User>,
) {}
2. @nestjs/bull (use @nestjs/bullmq)
// ❌ OLD — @nestjs/bull with @Process decorator
import { Process, Processor } from '@nestjs/bull';
@Processor('queue')
class MyProcessor {
@Process() async handle(job: Job) {}
}
// ✅ CURRENT — @nestjs/bullmq with WorkerHost
import { Processor, WorkerHost } from '@nestjs/bullmq';
@Processor('queue')
class MyProcessor extends WorkerHost {
async process(job: Job): Promise<void> {}
}
3. Express-specific middleware mistakes
// ❌ WRONG — Express req/res types in NestJS
import { Request, Response } from 'express';
@Get()
async findAll(@Req() req: Request, @Res() res: Response) {
res.json(data); // Bypasses interceptors, serialization, exception filters
}
// ✅ CORRECT — Use NestJS decorators, return values
@Get()
async findAll(@Query() query: FindAllQueryDto): Promise<UserResponseDto[]> {
return this.usersService.findAll(query);
}
// Only use @Res() when streaming files or SSE — add { passthrough: true }
@Get('download')
async download(@Res({ passthrough: true }) res: Response) {
res.set('Content-Type', 'application/octet-stream');
return new StreamableFile(stream);
}
4. Wrong decorator combinations
// ❌ WRONG — @Injectable() on a controller
@Injectable()
@Controller('users')
export class UsersController {}
// ❌ WRONG — @Controller() on a service
@Controller()
@Injectable()
export class UsersService {}
// ❌ WRONG — @Body() in a GET handler
@Get()
async findAll(@Body() body: any) {} // GET requests should not have a body
// ❌ WRONG — Both @Param and @Query with same name
@Get(':id')
async findOne(@Param('id') paramId: string, @Query('id') queryId: string) {}
5. class-validator / class-transformer mistakes
// ❌ WRONG — Validation without enabling in main.ts
// (AI often forgets this critical line)
// main.ts MUST have:
app.useGlobalPipes(new ValidationPipe({
whitelist: true, // Strip unknown properties
forbidNonWhitelisted: true, // Throw on unknown properties
transform: true, // Auto-transform payloads to DTO instances
transformOptions: {
enableImplicitConversion: true,
},
}));
// ❌ WRONG — Mixing validation decorators with wrong transform
export class CreateUserDto {
@IsString()
name: string;
@IsNumber()
age: string; // Type mismatch! Decorator says number, type says string
}
// ✅ CORRECT — Types match decorators
export class CreateUserDto {
@IsString()
@IsNotEmpty()
name: string;
@IsInt()
@Min(0)
age: number;
}
6. Async module pitfalls
// ❌ WRONG — useFactory without async when awaiting
TypeOrmModule.forRootAsync({
useFactory: (config: ConfigService) => ({
type: 'postgres',
url: config.get('DATABASE_URL'), // Not awaited, no inject
}),
})
// ✅ CORRECT
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (config: ConfigService) => ({
type: 'postgres',
url: config.getOrThrow<string>('DATABASE_URL'),
autoLoadEntities: true,
synchronize: false, // NEVER true in production
}),
})
Type Safety Rules
NEVER generate any
// ❌ BANNED
catch (error: any) { ... }
const data: any = await response.json();
private cache = new Map<string, any>();
// ✅ REQUIRED
catch (error: unknown) {
if (error instanceof DomainError) { ... }
throw error;
}
const data = await response.json() as PaymentGatewayResponse;
private cache = new Map<string, CachedSession>();
NEVER generate untyped event payloads
// ❌ WRONG
eventBus.emit('order.created', { order });
// ✅ CORRECT — Typed events
export class OrderCreatedEvent {
constructor(
public readonly orderId: string,
public readonly userId: string,
public readonly totalAmount: number,
public readonly occurredAt: Date = new Date(),
) {}
}
eventBus.emit(new OrderCreatedEvent(order.id, order.userId, order.total));
Configuration Safety
NEVER generate hardcoded values for:
- Database connection strings
- API keys or secrets
- Port numbers
- Feature flags
- External service URLs
ALWAYS use ConfigService with getOrThrow:
// ❌ WRONG
const port = process.env.PORT || 3000;
const dbUrl = process.env.DATABASE_URL;
// ✅ CORRECT
const port = this.configService.getOrThrow<number>('app.port');
const dbUrl = this.configService.getOrThrow<string>('database.url');
Database Safety
NEVER generate:
// ❌ synchronize: true in production config
// ❌ DROP TABLE or TRUNCATE in migration files
// ❌ Raw SQL without parameterized queries
await this.dataSource.query(`SELECT * FROM users WHERE id = '${userId}'`); // SQL injection!
// ✅ CORRECT
await this.dataSource.query(`SELECT * FROM users WHERE id = $1`, [userId]);
Remember
- If you're unsure whether a package exists, DO NOT import it. Ask or check.
- If you're generating a NestJS pattern you haven't seen in the official docs, STOP and reconsider.
- When in doubt, generate LESS code with correct patterns rather than MORE code with guesses.
No result recorded yet. Added it? File a Tried-it report so the next person knows how it went in your editor.
Tried it
Reports from people who added this rule to their editor. They roll up into the badges above.
No one has filed a report yet. Try the prompt and be the first.
Related rules
- Forensic PHP codebase security, performance and quality audit
A long checklist-driven prompt that has the model act as a senior PHP reviewer and audit a codebase for type safety, security holes, database and performance issues, code quality, architecture, dependencies, and testing gaps, then report findings by severity with a final scored summary.
Coding · @ersinkoc
- Agent role that turns TypeScript typing work into a tracked TODO plan
A senior TypeScript type-expert role prompt covering type design, generics, narrowing, and migration, with a required output of TODO_ts-type-expert.md containing checkable task items.
Coding · @wkaandemir
- Go backend coding spec for vertical domain modules using shanjunmei/dig
A system-prompt skill that makes the model act as a Go architect and generate or repair code with vertical domain modules, viper config loading, minimal naming, and a unified RegisterRoute handler method for shanjunmei/dig compile-time DI.
Coding · @shanjunmei
- Claude api: reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming,…
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER — read BEFORE opening the target file; don't skip because it "looks like a one-liner" — whenever: the prompt names Claude/Anthropic in any fo
Coding · @anthropic
- Nginx config security review with fixes and checker script
Agent skill that reviews nginx configs for TLS, header, alias traversal, admin exposure and rate-limit problems, runs a stdlib checker, and returns a minimal route-preserving fixed config with reload and curl test steps.
Coding · @f
License: CC0v1 · published Nov 29, 2026
Comments
No comments yet. If you tried this prompt, say how it went.