{"record":{"id":"1786936a6b675e76","repo":"spring-projects/spring-ai","slug":"schema-name-should-only-contain-alphanumeric-chara","errorCode":null,"errorMessage":"Schema name should only contain alphanumeric characters and underscores","messagePattern":"Schema name should only contain alphanumeric characters and underscores","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorSchemaValidator.java","lineNumber":84,"sourceCode":"\t\treturn true;\n\n\t}\n\n\tboolean isTableExists(String schemaName, String tableName) {\n\t\tString sql = \"SELECT 1 FROM information_schema.tables WHERE table_schema = ? AND table_name = ?\";\n\t\ttry {\n\t\t\t// Query for a single integer value, if it exists, table exists\n\t\t\tthis.jdbcTemplate.queryForObject(sql, Integer.class, schemaName, tableName);\n\t\t\treturn true;\n\t\t}\n\t\tcatch (DataAccessException e) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tvoid validateNames(String schemaName, String tableName) {\n\t\tif (!isValidNameForDatabaseObject(schemaName)) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Schema name should only contain alphanumeric characters and underscores\");\n\t\t}\n\t\tif (!isValidNameForDatabaseObject(tableName)) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Table name should only contain alphanumeric characters and underscores\");\n\t\t}\n\t}\n\n\tvoid validateTableSchema(String schemaName, String tableName, int dimensions) {\n\n\t\tvalidateNames(schemaName, tableName);\n\n\t\tif (!isTableExists(schemaName, tableName)) {\n\t\t\tthrow new IllegalStateException(\"Table \" + tableName + \" does not exist in schema \" + schemaName);\n\t\t}\n\n\t\ttry {\n\t\t\tif (logger.isInfoEnabled()) {","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorSchemaValidator.java#L66-L102","documentation":"PgVectorSchemaValidator.validateNames rejects schema names that are not purely alphanumeric with underscores. This guards against SQL injection and quoting problems when the schema name is embedded in identifiers and DDL queries.","triggerScenarios":"Constructing PgVectorStore (or PgVectorStore.builder) with a schema name containing hyphens, dots, spaces, quotes, or other non [A-Za-z0-9_] characters, with initialize-schema/validation enabled.","commonSituations":"Config value spring.ai.vectorstore.pgvector.schema-name copied from a connection string or environment-specific name like \"my-schema\" or \"dev schema\"; schema names derived from tenant IDs with dashes.","solutions":["Rename the schema in PostgreSQL to contain only alphanumerics and underscores (e.g. my_schema).","Sanitize the configured schema name before passing it to the builder.","Replace disallowed characters: schemaName.replaceAll(\"[^A-Za-z0-9_]\", \"_\")."],"exampleFix":"// before\nPgVectorStore.builder(jdbcTemplate, embeddingModel)\n    .schema(\"my-schema\").build();\n// after\nPgVectorStore.builder(jdbcTemplate, embeddingModel)\n    .schema(\"my_schema\").build();","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(schemaName, \"schema\");\nif (!schemaName.matches(\"[A-Za-z0-9_]+\")) {\n    throw new IllegalArgumentException(\"Schema name must be alphanumeric/underscore: \" + schemaName);\n}","typeGuard":null,"tryCatchPattern":"try {\n    PgVectorStore store = builder.build();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Schema name\")) {\n        throw new ConfigurationException(\"Fix spring.ai.vectorstore.pgvector.schema-name\", e);\n    }\n    throw e;\n}","preventionTips":["Validate schema-name config at application startup.","Keep schema names lowercase snake_case in all environments.","Never derive schema names directly from user or tenant input without sanitizing."],"tags":["pgvector","schema-validation","naming"],"backgroundTag":"invalid-identifier-format","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}